The CreatorCon Call for Content is officially open! Get started here.

How to set scratchpad values into catalog client script

Rani11
Tera Expert

Hi All,

I am trying to access display business rule scratchpad values into catalog client script but it always shows undefined. Can anyone help here. I think there is some minor mistake.

Actually there is a record producer to create an incident. Whenever the incident is created via the record producer, it will automatically assigned to service desk. But there I am trying to build one exclude condition.

Like if particular ci is selected, the it should go to "Team A Group" instead service desk . Only for that particular condition the assignment group should changed. There is a hidden reference variable in the record producer to do this. The hidden field is "assignment_group". So in the catalog client script i am trying to call the scratchpad and set the value but the scratchpad value shows undefined always. Am i doing any mistake here? 

Is there anyway that scratchpad value to be called and used in catalog client script?

Display business rule on "Incident" Form :

 

find_real_file.png

Catalog Client Script which tried to call the scratchpad on  :

find_real_file.png

 

 

1 ACCEPTED SOLUTION

Hi,

Script Include: It should be client callable

var GetProperty = Class.create();
GetProperty.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	getDetail: function(){
		
		return gs.getProperty('propertyName1') + '@' + gs.getProperty('propertyName2');
		
	},
	
    type: 'GetProperty'
});
function onChange(control, oldValue, newValue, isLoading) {
	if (isLoading || newValue == '') {
		return;
	}

	var ga = new GlideAjax('GetProperty');
	ga.addParam('sysparm_name', "getDetail");
	ga.getXMLAnswer(function(answer){
		if(answer != ''){
			var propertyValue1 = answer.split('@')[0];
			var propertyValue2 = answer.split('@')[1];

			// now compare

		}
	});
	//Type appropriate comment here, and begin script below

}

Regards
Ankur

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

View solution in original post

13 REPLIES 13

Brad Bowman
Kilo Patron
Kilo Patron

Hi Rani,

Have you confirmed that the BR logs show the correct values stored in the scratchpad variables?  Are both alerts showing undefined?  If you try alerting on the 2 scratchpad variables in an onLoad script are they also undefined?

It seems like it would be better to meet your requirement using one before Insert Business Rule on the incident table, unless you have a reason for waiting until the incident is viewed and whatever field this Client Script is running onChange of changes before the assignment group is changed.

Hi Brad,

Yes. When i do logs in BR it shows correct values in scratchpad.

In the client script both are "undefined".

I am using onchange catalog client script. Based on ci selection, the hidden assignment group field  to be set with this scratchpad value.

I have created BR table name as "incident". Is that correct here?

It should work only for record producer created incident and its not applicable to normal case. So that is the reason i am trying to do something in the catalog client script itself.

The BR table is correct.  If your onChange script is a catalog client script then it must be defined in the Record Producer?  If so it is running on the record producer, not the incident record - because the record hasn't been created yet, so the display business rule will not have triggered yet. If you don't need to see the assignment group get set/changed (before the RP is submitted) put your code into the Script on the record producer.  This behaves like a server script, so you can use gs.getProperty... then assign the value using current.assignment_group = (property var or gs.getProperty...)