Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- #Save this script to your [OTHOME]\scripts directory, then...
- #update your opentext.ini file as follows.....
- #update loader section's "load=" statement, add the ";kstateexample" expression to the end, like this...
- [loader]
- load=sockserv;javaserver;notify;wfagent;agents;kstateexample
- #add this new section
- [kstateexample]
- lib=.\bin\lljob.dll
- name=kiniexample
- prio=critical
- timeout=5000
- info=.\config\opentext.ini;kstateexample
- StartScript=.\scripts\llfull.lxe
- JobScript=.\scripts\kstateexample_run.e
- CRON=* * * * *
- SleepIntervalSec=10
- */
- function Dynamic JobScript( \
- Assoc params, \
- Dynamic notCtxOut )
- Dynamic retval
- Record r
- Dynamic ctxin
- Dynamic err
- Dynamic debugLevel
- FilePrefs prefs
- String filePrefsName
- String activityIDsStr
- String excludeActivityIDsStr
- File ctxout
- Object agent
- Frame f
- List agentList = {}
- List excludeAgentList = {}
- String logPath = './logs/'
- String section = 'notify_run'
- // get preference section
- if ( IsFeature( params, '_LLJOB_SECTION_NAME_' ) )
- section = params.( '_LLJOB_SECTION_NAME_' )
- end
- String runLog = Str.Format( "%1_run%2.html", section, System.ThreadIndex() )
- // get preference file path
- if ( IsFeature( params, '_LLJOB_CONFIG_FILE_' ) )
- filePrefsName = params.( '_LLJOB_CONFIG_FILE_' )
- else
- filePrefsName = System.FilePrefsPath()
- end
- if !File.Exists( filePrefsName )
- echo( Str.Format( "Can not find configuration file: '%1'.", filePrefsName ) )
- else
- prefs = FilePrefs.Open( filePrefsName )
- if ( IsUndefined( prefs ) || IsError( prefs ) )
- echo( Str.Format( "Could not open prefs '%1'.", filePrefsName ) )
- end
- end
- logPath = GetMyPrefPath( prefs, section, 'Logpath', logPath ) + runLog
- activityIDsStr = GetMyPref( prefs, section, 'ActivityIDs', '' )
- debugLevel = Str.StringToValue( GetMyPref( prefs, section, 'Debug', '0' ) )
- FilePrefs.Close( prefs )
- // open per request run log based on preferences
- ctxout = File.Open( logPath, File.WriteMode )
- echo("[KSTATEEXAMPLE] start")
- echo("[KSTATEEXAMPLE] Call to GetKiniParam('RecMan','holdsFolderID'): ", GetKiniParam('RecMan','holdsFolderID'))
- echo("[KSTATEEXAMPLE] stop")
- // close log file
- File.Close( ctxout )
- if ( IsDefined( err ) )
- echo( "Job error: ", err )
- retval = err
- else
- echo( Date.Now(), " completed SUCCESS" )
- end
- return 0
- end
- // check both section passed and the [general] sections
- function String GetMyPrefPath( FilePrefs prefs, String section, String prefName, String defReturn )
- String retVal = defReturn
- if ( IsDefined( prefs ) || !IsError( prefs ) )
- retVal = FilePrefs.GetPath( prefs, section, prefName )
- if ( IsError( retVal ) || IsUndefined( retVal ) )
- retVal = FilePrefs.GetPath( prefs, 'general', prefName )
- if ( IsError( retVal ) || IsUndefined( retVal ) )
- //echo( "Could not find preference :" , prefName )
- retVal = defReturn
- end
- end
- end
- return retVal
- end
- // check both section passed and the [general] sections
- function String GetMyPref( FilePrefs prefs, String section, String prefName, String defReturn )
- String retVal = defReturn
- if ( IsDefined( prefs ) || !IsError( prefs ) )
- retVal = FilePrefs.GetPref( prefs, section, prefName )
- if ( IsError( retVal ) || IsUndefined( retVal ) )
- retVal = FilePrefs.GetPref( prefs, 'general', prefName )
- if ( IsError( retVal ) || IsUndefined( retVal ) )
- //echo( "Could not find preference :" , prefName )
- retVal = defReturn
- end
- end
- end
- return retVal
- end
- function Object GetPrgCtx(String username)
- Assoc dbCredentials
- Assoc tmpVal
- Object prgCtx
- Dynamic dftConnection
- String msg
- prgCtx = Undefined
- dftConnection = $Kernel.SystemPreferences.GetPrefGeneral( 'DftConnection' )
- dbCredentials.Ok = true
- dbCredentials.User = Username
- dbCredentials.Password = Undefined
- dbCredentials.DBConnection = dftConnection
- tmpVal = $LLIApi.PrgSession.CreateNewNamed( \
- dbCredentials.DBConnection, \
- { dbCredentials.User, dbCredentials.Password } )
- if ( tmpVal.ok )
- prgCtx = tmpVal.pSession
- else
- prgCtx = Undefined
- msg = Str.Format( \
- "Failed to create a prgCtx. Reason: %1" \
- ,tmpVal.ErrMsg )
- echo( msg )
- end
- return prgCtx
- end
- function Assoc GetKiniParam(String section, String key, Object prgCtx = Undefined)
- Assoc retVal
- retVal.ok = false
- retVal.ErrMsg = Undefined
- retVal.Value = Undefined
- Dynamic value
- if (IsUndefined(prgCtx))
- prgCtx = GetPrgCtx("Admin")
- end
- value = capi.IniGet(prgCtx.fDBConnect.fLogin, section, key)
- if (IsError(value))
- retVal.ErrMsg = Error.ErrorToString(value)
- else
- retVal.Value = value
- retVal.ok = true
- end
- if (!retVal.ok)
- if (IsUndefined(retVal.ErrMsg))
- retVal.ErrMsg = Str.Format("Failed call to get Kini Parameter for unknown reason.")
- end
- end
- return retVal
- end
Advertisement
Add Comment
Please, Sign In to add comment