Set a choice list value from record producer script.

Sam Ogden
Tera Guru

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:

find_real_file.png

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.

find_real_file.png

In the record producer script I have the following:

find_real_file.png

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

1 ACCEPTED SOLUTION

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


View solution in original post

25 REPLIES 25

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


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.


Valentina6
Giga Guru

Hi Sam,


  1. Add this line at the end: gs.log('SAM: '+current.u_number_of_operators_affected+','+current.u_number_of_policies_affected+','+current.urgency);
  2. Run the business rule
  3. 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


Hi Valentina,



Thanks for your detail above.   Just to confirm, the above script is not a business rule, but is the record producer script.


I've added the line to the end of the script, and checked in 'script log statements', but I am not seeing anything:



find_real_file.png


find_real_file.png



Thanks



Sam


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