- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā08-04-2020 01:17 PM
Hello Master coders:
I am in need of a script that would allow me to pass values from fields in variables that are located in a RITM into a Standard Change Request field (I am using a UI action to create the CHG Req from the RITM)
So for example:
Name = Snow
City= New York
Country = USA
I need the values to append to a Description Field that reads likes this:
Provide the following:
Name:
City:
Country:
Basically I need to be able to pass the values of Name, City & Country into the predetermined text that is already populated into the Description Template and they should be placed correctly and after the colon.
I hope this makes sense and I appreciate any help.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā08-04-2020 01:46 PM
If your UI Action is running on the sc_req_item table, use current.variables.variable_name to access those values. As long as Name, City, and Country are all text variables, and assuming description is a long string field it's going to be easiest to wipe the field value and rebuild it with your variable values, so something like this
var name = current.variables.name;
var city = current.variables.city;
var country = current.variables.country;
var desc = 'Provide the following:\n Name: ' + name + '\nCity: ' + city + '\nCountry: ' + country;
Then use desc to update the field on the newly-created change request. If name or any of these are reference variables, then you'd have to do a GlideRecord to lookup the display value first.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā08-04-2020 05:02 PM
I'm assuming we're talking about a single string field that you are populating in a Standard Change Template. So if you did nothing to this field when you create a change, the incomplete text will be there within the Description field. If you were to look at the value stored in that field, it would be a single string. This is why you can't just append 3 values after the colons - there's a few ways to do it, but you end up with a new complete single string in any event that needs to be saved to the description field. Your change request creation steps are going to include setting the value of the Description field to this new string, so it will replace what's already there - just the same as if you were to populate Assignment group, Service, or any other field that isn't part of the template. The question is when creating the change request via a UI Action, which will happen first, so what will be the resulting value on the created record - the incomplete template value, or your new complete string? Give it a try and see. If the template wins you can try to add to your UI Action script to immediately update this field on the newly-created record, or another option is to populate your complete description string in another field that is unused upon creation, like Test plan or something other than Description, then add an after insert Business Rule that copies Test plan to Description, then clears Test Plan - same end result, and the template stays as it is for changes created outside of this UI Action.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā08-04-2020 05:13 PM
Thank you so much for you help with this.
I will try this first thing tomorrow morning and will reply to the post.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā08-13-2020 10:55 AM
Hi Brad:
So the Template wins, I was able to pass the entire string into another field and that works but i have not been able to come up with a script that will make the after BR move the values from close_notes into description and then delete it.
If you have a moment, could you please help me out with this part?
Thank you so much.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā08-13-2020 11:59 AM
I have tried some simple things even just to set the description field to just empty with a BR I also placed a gs.addInfomsg and the msg show sup but is not affecting the fields and nothing happens. That template is a wicked thing.