The Zurich release has arrived! Interested in new features and functionalities? Click here for more

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

@Mohith Devatte I could not find the Hr case sys id in this table you mentioned. Please suggest.

Can you attach the screenshot in attachments i am not able to see the image

 

@Mohith Devatte  Added image in attachment, please check

Harish KM
Kilo Patron
Kilo Patron

Tried in instance by commenting few lines works well


    var grlecase1 = new GlideRecord('sn_hr_core_case'); 
//grlecase1.addQuery('subject_person.email', 'Alice.Tester@testemail.com');
grlecase1.addQuery('sys_id', '1001e3fd07f70110f1cbf48f7c1ed0cb'); // added for testing 1 record by using sysid
//grlecase1.addQuery('hr_service', 'a83f55e487a811502413b919cebb3577');
grlecase1.setLimit(1);
grlecase1.query();

if(grlecase1.next()){
    var dt = new GlideDate();
    dt.setDisplayValue('2022-07-11');
grlecase1.short_description = dt;
    //grlecase1.variables.employment_start_date = dt; // make sure variable name is correct
    grlecase1.setWorkflow(false);
    grlecase1.update();
}

Regards
Harish

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

BR is on which table?

BR is in which scope?

That variable is in which scope?

try this

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.setValue('2022-07-11');
    grlecase1.variables.employment_start_date = dt;
    grlecase1.setWorkflow(false);
    grlecase1.update();
}

Regards
Ankur

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