- 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-02-2017 09:58 AM
Hi Valentina,
Thanks for the above. I am new to scripting and not up to speed on using gs.log. Below is my entire script. Could you provide an example of adding in the gs.log:
I would assume that it is getting that far down the script though as the short description is getting correctly set on the form which is the line before these 3 values.
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_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.u_environment = env;
current.short_description = short_description;
current.u_number_of_operators_affected = "2";
current.u_number_of_policies_affected = "2";
current.urgency = 2;
Thanks
Sam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2017 05:36 AM
Sam, I see in your script you are setting current.u_environment twice (lines 35 and 44). The second instance you are setting it to an object versus a SysID. Try the following script to see if it works. Notice line 44 is commented out. If this script works, just remove this line.
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_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.u_environment = env; //this is a duplicate of a line above and may be causing the error
current.short_description = short_description;
current.u_number_of_operators_affected = "2";
current.u_number_of_policies_affected = "2";
current.urgency = 2;
Edit: just noticed a space on line 13 between the word "next" and the parenthesis and corrected, maybe that is causing issues too.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2017 01:21 AM
Hi Sam,
- Add this line at the end: gs.log('SAM: '+current.u_number_of_operators_affected+','+current.u_number_of_policies_affected+','+current.urgency);
- Run the business rule
- Check in System Logs > System Log > All.
If the variables are null, the script is the cause, otherwise if the variables are not null, there is something else that runs after your business rule and modifies the values.
Hope it helps!
Regards,
Valentina
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2017 02:11 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2017 02:46 AM
Sam this means that the gs.log script row is not processed. I suggest you to add various 'gs.log' in your code in order to identify where the error is located.
Let me know.
Regards,
Valentina