Copy REQ Variables to SC_TASK Description

Adam H1
Tera Expert

I am new to scripting, but I just completed the Scripting in ServiceNow Fundamentals class and I am trying to put some of what I learned to work.  It's not coming easy to me, yet. 

 'description_of_request' is part of a variable set on some of our catalog items.  When a request is submitted we want the 'description_of_request' written to 'description' and 'short_description' fields on the RITM and the SCTASK.  I wrote the following script in a business rule that  works as intended for RITM.  However, I cannot figure out how to modify this script to do the same for the SCTASK.  How would you modify this script to also set the 'description' and 'short_description' fields on the SCTASK = description_of_request?

 

find_real_file.png

(function executeRule(current, previous /*null when async*/ ) {
    //Query sc_req_item and match on current.request
    //Update short_description and description of req_item with description_of_request from variable set

    var grRITM = new GlideRecord('sc_req_item');

    grRITM.addQuery('request', current.request);

    grRITM.query();

    while (grRITM.next()) {

        current.short_description = grRITM.variables.description_of_request;
        current.description = grRITM.variables.description_of_request;
		
        grRITM.update();
    }


})(current, previous);

 

1 ACCEPTED SOLUTION

Sure, I have tried your requirement in my PDI and have got that working now.

Please find the steps below:

1) Create a Before Insert and Update Business Rule on Requested Item table and use the script below:

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

	// Add your code here
	current.short_description = current.variables.Variable Name; // Replace "Variable Name" with your variable name
	current.description = current.variables.Variable Name; // Replace "Variable Name" with your variable name

})(current, previous);

find_real_file.png

find_real_file.png

Now create another Before Insert and Update Business Rule on Catalog Task table and use the script below:

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

	// Add your code here
	current.short_description = current.request_item.short_description;
	current.description = current.request_item.description;

})(current, previous);

find_real_file.png

This works for me in my PDI. Let me know if still you are facing an issue.

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

24 REPLIES 24

Can you just make your BR as After Insert and Update instead of using Before as shown below:

find_real_file.png

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hi. I changed the BR to run AFter Insert or Update.  Now, neither the fields on the RITM or SCTASK are being updated. 

Configuration:

find_real_file.png

Results:

find_real_file.png

Sure, I have tried your requirement in my PDI and have got that working now.

Please find the steps below:

1) Create a Before Insert and Update Business Rule on Requested Item table and use the script below:

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

	// Add your code here
	current.short_description = current.variables.Variable Name; // Replace "Variable Name" with your variable name
	current.description = current.variables.Variable Name; // Replace "Variable Name" with your variable name

})(current, previous);

find_real_file.png

find_real_file.png

Now create another Before Insert and Update Business Rule on Catalog Task table and use the script below:

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

	// Add your code here
	current.short_description = current.request_item.short_description;
	current.description = current.request_item.description;

})(current, previous);

find_real_file.png

This works for me in my PDI. Let me know if still you are facing an issue.

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

That worked!  And, how you did it makes perfect sense to me. It's nice and simple.  Thanks so much for the help. Our users are going to love this improvement. 

 

Adam

Adam H1
Tera Expert

Here are a couple of screenshots from my business rule including your script: