Run Script Activity Scripting Example

// Select all Inchidents where the value in the 'rfc' field is equal to the current record's sys_id

var incGR = new GlideRecord('incident');
incGR.addQuery('rfc', current.sys_id);
incGR.query();

while (incGR.next()){
    //Add the Incident's Caller to the current 'watch_list' if they have the 'itil' role
    if (incGR.caller_id.roles.indexOf('itil') != -1){
        if(current.watch_list == ''){
            current.watch_list = incGR.caller_id.sys_id;
        }
        else{
            current.watch_list = current.watch_list + ',' + incGR.caller_id.sys_id;
        }
    }
}

The sample script queries the Incident table for the records where the value in the 'rfc' field is equal to the current Change Request's sys_id, then updates the watch_list field with the Incident caller's sys_id if that user has the 'itil' role.

The indexOf() method returns the position of the first occurence of a specified value in a string. It returns -1 if the value to search for never occurs.

results matching ""

    No results matching ""