How to Update existing HR Profile from the record producer when submitted the form

Ram33843094
Tera Contributor

 

On the record producer we've mapped to field for LE case table. Then wrote a after insert business rule where im trying to map variable value from LE case table to HR profile table.

 

(function executeRule(current, previous /*null when async*/) {

var hr= new GlideRecord('sn_hr_core_profile');
hr.addQuery('sys_id',current.subject_person);
hr.query();
while(hr.next()){


hr.location=current.location.toString();
hr.update();

gs.log('test:' + location);

}

})(current, previous);

 

@Ankur Bawiskar 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Ram33843094 

please update as this

1) don't use gs.log() in scoped app as it will break the script

2) also you need to use current.variables to access variable value

(function executeRule(current, previous /*null when async*/) {

	var hr= new GlideRecord('sn_hr_core_profile');
	hr.addQuery('sys_id',current.subject_person);
	hr.query();
	if(hr.next()){
		hr.location = current.variables.location.toString();
		hr.update();
	}

})(current, previous);

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

View solution in original post

1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

@Ram33843094 

please update as this

1) don't use gs.log() in scoped app as it will break the script

2) also you need to use current.variables to access variable value

(function executeRule(current, previous /*null when async*/) {

	var hr= new GlideRecord('sn_hr_core_profile');
	hr.addQuery('sys_id',current.subject_person);
	hr.query();
	if(hr.next()){
		hr.location = current.variables.location.toString();
		hr.update();
	}

})(current, previous);

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