Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Unable to update Variable value in the Business rule

Mrman
Tera Guru

Hi All,

I have one after BR  where i have need to update the variable on the HR case with a new value .This variable is of type date. 

I am trying the below script to update the employment start date variable, but it is not working . Please suggest

var grlecase1 = new GlideRecord('sn_hr_core_case'); 
grlecase1.addQuery('subject_person.email', 'Alice.Tester@testemail.com');
grlecase1.addQuery('active', 'true');
grlecase1.addQuery('hr_service', 'a83f55e487a811502413b919cebb3577');
grlecase1.setLimit(1);
grlecase1.query();

if(grlecase1.next()){
	var dt = new GlideDate();
	dt.setDisplayValue('2022-07-11');
	grlecase1.variables.employment_start_date = dt;
	grlecase1.setWorkflow(false);
	grlecase1.update();
}

@Ankur Bawiskar 

14 REPLIES 14

Tudor
Tera Guru

Hello,

Could you please add a log within the if to see whether it identifies the case?

Also, I don't see you updating any data variable(you are not using dt anywhere).

Please try and provide feedback.

 Tudor

 

 

Hi ,

Please see the updated script . 

I added the log and it is showing log corecttly.

var grlecase1 = new GlideRecord('sn_hr_core_case'); 
grlecase1.addQuery('subject_person.email', 'Alice.Tester@testemail.com');
grlecase1.addQuery('active', 'true');
grlecase1.addQuery('hr_service', 'a83f55e487a811502413b919cebb3577');
grlecase1.setLimit(1);
grlecase1.query();

if(grlecase1.next()){
gs.info("the variables sdate is -----: " + grlecase1.variables.employment_start_date);
	var dt = new GlideDate();
	dt.setDisplayValue('2022-07-11');
	grlecase1.variables.employment_start_date = dt;
	grlecase1.setWorkflow(false);
	grlecase1.update();
}

I just tried the following code in a PDI and it works like a charm:

var gr = new GlideRecord("sc_req_item");
if (gr.get("8a3d43bc8764111036520f69cebb3567")){
    gs.info("The set date is " + gr.variables.test);
    var gd = new GlideDate();
    gd.setDisplayValue("2022-12-12");
    gr.variables.test=gd;
    gr.update();
    gs.info("The set date is " + gr.variables.test);
}
 
So my assumption is that something is blocking the update.
Could you please:
  1. check the logs to see whether there are any errors
  2. debug all and see what ACLs/BRs are triggered 

Tudor

@Mrman Also check the scopes and cross-scope access.