Business rule to update INC based on CAT item

dagarson
Tera Guru

Hello I have a catalog item that is suppose to update a Incident after submission but I seem to be having problems with the script. The idea is that on the catalog item you select the incident you wish to update, the values like the current inc short description are populated. 

find_real_file.png

When you submit whatever changes you made should then update the incident referenced in the field. I am doing this via a business rule but seem to be having some trouble here is my code.

 

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

var gr = new GlideRecord("incident");
	gr.addQuery('number', current.variable_pool.incident);
	gr.query();
while (gr.Next()){
		gr.caller = current.variable_pool.caller;
		gr.short_description = current.variable_pool.short_description;
		gr.description = current.variable_pool.description;

	}


})(current, previous);

I should note the business rule triggers "after" insert of the catalog item.

Any assistance would be helpful thank you.

1 ACCEPTED SOLUTION

dagarson
Tera Guru

Thank you all for your help it seems like the issue was a combination on what you all mentioned.

1. I had accidently made "Next()" capitalized.

2. I forgot the gr.update()

3. the variable for incident was mapped to sys id so I dot walked to incident.number.

4. Changing to a before business rule helped also.

 

Thank you for your assistance. 

View solution in original post

8 REPLIES 8

Hi @dagarson 

 

gr.next()

 

find_real_file.png

Thanks,
Shakeel Shaik 🙂

Hi @dagarson 

 

Here in your Catalog Item, you are using Reference field for Incident.

 

It will return sys_id

Thanks,
Shakeel Shaik 🙂

Sam211
Tera Expert

Don't you need gr.update() to write the info to the record, just like your query is not executed until you gr.query()?

dagarson
Tera Guru

Thank you all for your help it seems like the issue was a combination on what you all mentioned.

1. I had accidently made "Next()" capitalized.

2. I forgot the gr.update()

3. the variable for incident was mapped to sys id so I dot walked to incident.number.

4. Changing to a before business rule helped also.

 

Thank you for your assistance.