- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2017 07:49 AM
Hi All,
I've created a record producer for some incidents. All the incidents created via this record producer will be Sev 2 so we are not asking them a severity question.
I have been trying to set the value of the questions in the record producer script but not having any luck.
Back end incident form has the following fields:
The answer to 'number of users affected' & 'number of transactions affected' set the value of the 'impact' field.
Then the answers to 'impact' & 'urgency' then set the value for 'severity'
Below is an example of how the choices are setup.
In the record producer script I have the following:
I have also tried with '2' and "2" and still it does not set the value in the back end incident form.
Any help as to where I am going wrong is greatly appreciated.
Thanks
Sam
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2017 05:15 AM
Thanks Michael, I was not aware.
Sam the only way now is locate the error using gs.log. Maybe you can also copy the last three rows of your script in a new record producer, it will work.
Regards,
Valentina
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2017 04:52 AM
If the variable name value matches a column name in the target produced record, it will map it. That's what the "map to field"is doing behin the scenes. I agree with Valentina that the script must be error in general somewhere thus not getting to the bottom portion of the script. Put a gs.log statement at the very top and at random spots in the script. you should hopefully get some logging to help narrow down where the issue is.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2017 05:15 AM
Thanks Michael, I was not aware.
Sam the only way now is locate the error using gs.log. Maybe you can also copy the last three rows of your script in a new record producer, it will work.
Regards,
Valentina
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2017 06:00 AM
Thanks Michael, I was not aware.
Valentina, yes this appears to be a lesser known feature. When I started using ServiceNow 6 years ago the "map to field" option on record producer variables didn't exist so you had to remember to set the name attribute to the database field name in the produced record. With the introduction of the map to field, behind the scenes it is setting the name attribute to the database field name automatically. Here is the old Wiki article that explains:
Create a variable on the record producer with the same name as the field in the target record. For example, a variable named caller_id on a Create a New Incident record producer populates the caller_id field on the new incident record. Use a variable type that corresponds to the field type.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2017 06:14 AM
Thanks Michael,
I was also unaware that it auto mapped if they had the same name - very handy to know.
I've got it to work, I've moved the position of the 3 fields within the script and they now works. I will continue to see if I can find out what the error was. script now is:
var cat;
var subcat;
var assigngrp;
var prod;
//if statement to not run the rest of the code if the field is blank
if(producer.more_details_answer!=""){
// set the variable that will be the new gliderecord and say which table you want to run the query against
var ans2 = new GlideRecord('u_incident_assignment_rule');
// This is the query, it will automatically be set to equals - first is the value in the table you are checking, second is the value you are checking for
ans2.addQuery('u_csm_question_value', producer.more_details_answer);
ans2.query();
//checkes that this is the only record and then populates the previously definied variables
if(ans2.next ()) {
cat = ans2.u_category;
subcat = ans2.u_subcategory;
assigngrp = ans2.u_assignment_group;
prod = ans2.u_product;
}
}
var env = new GlideRecord('cmdb_ci_environment');
if (producer.inc_rel_to !=("test")){
env.addQuery('name', producer.issue_env);
env.query();
if(env.next()) {
var ans = env.sys_id;
}
}
else {
env.addQuery('name', producer.hidden_environment);
env.query();
if(env.next()) {
var ans = env.sys_id;
}
}
current.u_number_of_operators_affected = "2";
current.u_number_of_policies_affected = "2";
current.urgency = 2;
current.u_environment = ans;
current.state = 1;
current.u_customer_reference = producer.u_ref;
current.caller_id = gs.getUserID();
current.contact_type = 'self-service';
current.u_product = prod;
current.category = cat;
current.u_subcategory = subcat;
current.assignment_group = assigngrp;
current.short_description = short_description;
The category, subcategory and assignment group are all working and as you have mentioned the short description is auto mapping.
Thanks for all your help,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2017 06:18 AM
Great to hear you got it working. I see you removed the duplicate assignment of the u_environment field. I bet that was the issue. During the execution of a script if there is an error, the script stops running. With you setting those fields AFTER that, I suspect that is why they were never set.