how to get a variable on request item to populate on the catalog item short description

humblecommitted
Kilo Guru

Hello Community,

I am trying to get a variable called "ritm_short_description" on the catalog item to populate the "short_description" field on the request item.

Here is the catalog item:

find_real_file.png

Here is the variable on the catalog item:

find_real_file.png

Here is how I would like it to be displayed as after the catalog item has been submitted and is now a request item:

find_real_file.png

find_real_file.png

I have been trying workflows and business rules and i am not sure what i am doing wrong.

find_real_file.png

find_real_file.png

Please help!

Thanks in advanced.

1 ACCEPTED SOLUTION

Did you try this in the workflow in the run script activity. This run script activity should be your first activity in the workflow. Or you could also write a before business rule on the sc_req_item table



Run script activity:


current.short_description=current.cat_item.short_description+' '+current.variables.ritm_short_description;



Business rule:


When: before insert


Conditions: Item is <select the catalog item>


Script:


current.short_description=current.cat_item.short_description+' '+current.variables.ritm_short_description;


View solution in original post

13 REPLIES 13

Hello Abhinay,



Your method worked.



I wish I can give you all credit for the answer!



Here are the screen shots of the script


find_real_file.png


find_real_file.png



if(current.short_description.indexOf(current.variables.ritm_short_description) < 0) {


        current.short_description = current.short_description+" "+current.variables.ritm_short_description;


}



Glad you got it working.


Hello, is the business rule setup to run "before" or "after"? If you do it "after", you need to have "current.update();". I recommend executing it as "before" rule for simple things like that. This will ensure all changes to the current record happen at once. Also, note that the logic I gave is good for "insert". If you have a use case like the variable getting changed later on, you need to do it differently.



Here is roughly how you would have in a business rule that is setup to run "before" and for insert/update cases. The idea is that you are always building the new description based on the catalog item short description and the variable and comparing it to what's in the request item short description.



var newDescription = getShortDescription(current);


if(current.short_description != newDescription)


        current.short_description = newDescription;



function getShortDescription(gr /* ritm gr */) {


        var cat_short_description = gr.cat_item.short_description;


        if(gr.variables.my_variable) {


                  return gr.cat_item.short_description+" "+gr.variables.my_variable;


        }


        else


                  return gr.short_description;


}


Moe information on why before business rule is. You need to use before business rule when you are updating something on the current record and use after business rule when you are updating something on the related records not the current record. Also never use current.update() since it triggers business rules to run on the same table for insert and update operations, leading to a business rule calling itself over and over.


http://wiki.servicenow.com/index.php?title=Business_Rules_Best_Practices#gsc.tab=0