Copying A Variable Value Into A Field Form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2014 07:47 AM
We have numerous Catalog Items, where the request type is captured in the variable.
For example, "Email" is the Catalog Item, and "New Access", "Group Mailbox", "Distribution List" is captured within a variable.
With a business rule, I can copy the value of the variable onto the field on the Requested Item table.
current.u_item_type = current.variable_pool.email_access_list.getDisplayValue();
The issue I am experiencing however, is how do I expand that business rule?
If i have 50 Catalog Items, and I always want the "request type" value to populate into the Requested Item form. How should I go about doing that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2014 10:35 AM
Here's an idea - instead of doing it with a Business Rule, how about setting the field in a "Run Script" activity in your workflow(s)? If your catalog items share workflows, this might do and be less work (depends on your variable names).
If that is not possible nor practical, and you are forced into doing it with a Business Rule, this is how I would do it:
- add a new True/False field on the Catalog Item table ("Copy Item Type" or similar). This is the table where you define the catalog item itself and allows to pick and choose which items the Business Rule should run on.
- add a condition on your Business Rule to trigger off the new field when it is checked
- you will have to go through a few if else if statements to get the value of your variables because they have different names
The "Before Insert" Business Rule would look something like this:
Condition: current.cat_item.u_copy_item_type == true
Script:
(function(){
var answer = "";
answer = (current.variable_pool.email_access_list.getDisplayValue() + "").replace("undefined","");
if (answer == "") {
answer = (current.variable_pool.something_else.getDisplayValue() + "").replace("undefined","");
}
if (answer == "") {
answer = (current.variable_pool.try_again.getDisplayValue() + "").replace("undefined","");
}
current.u_item_type = answer;
})();
It's not pretty, but you need to go through your different variable names. If nothing is found, it tries another variable name and so on. The "answer" variable is set to undefined (not a string) when the variable is not found, so we need to force it to a string and then remove that "undefined" string.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2014 01:45 PM
If that solves your issue, can you please mark the question as being answered in order to help out others? Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2014 03:06 AM
Hi Rachelle,
Maybe below article helps you to solve the problem.
http://www.servicenowguru.com/scripting/business-rules-scripting/variables-form-readonly/
Regard
Artur
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2014 08:00 AM
Thanks Arthur, What is mentioned in the article is a little different then what I am trying to do.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2014 08:41 AM
Hi Rachelle,
Do you know that you can map a variable to a field by naming the variable the same as the field? This has become easier in Eureka where you can pick a mapping, but in prior versions you can simply name the variable.