scheduled job execution

dvelloriy
Kilo Sage

Hello All

I have a scheduled job which is getting triggered however it is not executing the script. Please find the snapshot below.

As per script, it should update the target HR case from suspended to work in progress and update the assignment group as well. However that is not happening.

Can someone please advise? Can we validate why its not working, is there something wrong with script or is it cross scope issue?

 

Script:

 

var gr = new GlideRecord("sn_hr_core_case_workforce_admin");

if (gr.get("0710fb561bc8a2d08dc18402604bcbcd"))

{ gr.assignment_group = "2c52d0031bb98ed0e89734cf034bcb99";

gr.state=10;

gr.assigned_to="";

gr.update();

}

 

dvelloriy_0-1741277017631.png

 

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

@dvelloriy 

can you try this and see what came in logs?

scheduled job is in which scope?

any cross scope error?

var gr = new GlideRecord("sn_hr_core_case_workforce_admin");
if (gr.get("0710fb561bc8a2d08dc18402604bcbcd"))
{
	gs.info('Record found');
    gr.assignment_group = "2c52d0031bb98ed0e89734cf034bcb99";
    gr.state = 10;
    gr.assigned_to = "";
    gr.update();
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur,

 

I inserted the logs. and see below error in the logs. I dont see "Record found".

 

**Source descriptor is empty while recording access for table sn_hr_core_case_workforce_admin: no thrown error

@dvelloriy 

job is configured in which scope?

Please create a scheduled job like this in correct HR scope. It seems your script is not in correct HR scope

Create a scheduled job 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Ankur,

 Job is in global scope I guess. I am creating the schedule using the flow variable you suggested earlier. How can i change the scope here?

Do you think we might have to change the strategy here and make a call using a scirt include instead and create restrict caller access for that script include?

Please advise.

 

Here is the script:

 

// Schedule a job to reassign to Group B when it reaches the 30-day mark
    var scheduledJob = new GlideRecord('sys_trigger');
scheduledJob.initialize();
scheduledJob.name = 'Assign to Recruitment and Onboarding group';

// Correcting the date calculation
var scheduledDate = new GlideDateTime(effectiveDate);
scheduledDate.addDaysLocalTime(-30);
scheduledJob.next_action = scheduledDate.getValue(); // Ensure correct assignment
scheduledJob.trigger_type = 0;
// Assign the script to update the record
scheduledJob.script = 'var gr = new GlideRecord("' + tableName + '"); if (gr.get("' + triggerRecordSysId + '")) { gr.assignment_group = "' + groupB + '";gr.state=10;gr.assigned_to=""; gr.update(); }';

scheduledJob.insert();
   
}