Get field value of Record Producer field in Business Rule

Andrew122
Mega Expert

Hello,

I have a Record Producer that has a couple of custom fields that aren't on the Record that it is creating.  Is there a way to get the value of what is in that Record Producer field through a Business Rule?

So if I have a "Test" field that is on the Record Producer but not on the table with a name of "u_test" could I get the value of that field in a Business Rule and push that value into a Short Description field?

1 ACCEPTED SOLUTION

Andrew, 

 

       I think I follow this requirement, let us explore this request more through real table names because I think you referenced the wrong table at the end. 

You have a Record Producer with a Variable (u_test) the Record Producer generates an Idea Record on Submit. You need to take the Idea Record Variable and write it to an existing Incident Record Field (u_number). I am not sure how you will query the Incident table to target the correct record because I do not follow how the Incident Record will have a reference to the Idea Record through the number field as you stated.

The method could be an after insert BR but this will only pass the Record Producer Record Variable (u_test), on the 'Idea Table' to all Incidents without a value in the Incident.u_number field on the Incident table. 

(function executeRule(current, previous /*null when async*/) {

     var rec = current.variables.u_test.toString();
     var gr = new GlideRecord('incident');
     gr.addQuery('u_number','');
     gr.query();
     while (gr.next) {
          gr.u_number = rec;
     }

})(current, previous);

 

Thanks, 

 

Derrick Johnson

View solution in original post

7 REPLIES 7

djohnson1
Mega Guru

Andrew, 

 

     In the record producer record, add the below script line based on the record producer variable type. 

 

If 'test' is a string value:

current.short_description = "blah " + producer.test

If 'test' is a reference value: 

current.short_description = "blah " + producer.test.getDisplayValue();

      Assumption-- the name value of the field you are wanting to write to on the 'u_test' table is short_description.

 

Thanks, 

 

Derrick Johnson

Prateek kumar
Mega Sage

Why would you need a Business rule for that.

You can concatenate the value of your test field on the record producer and make it populate on the SD field at the time of record creation.

Try this in your record producer script.

current.short_description  = producer.shortdescription_variable_name + '\n'producer.testvariable_name;

https://docs.servicenow.com/bundle/london-it-service-management/page/product/service-catalog-managem...


Please mark my response as correct and helpful if it helped solved your question.
-Thanks

Cody Smith _ Cl
Tera Guru

Hello Andrew,

I think what you're saying is the filed on the record producer is a dot walked field from somewhere else? You would just push the value of that field to the short description. So something like this, you would need to get the correct field names. 

var testField = current.field_1.test.getDisplayValue();
current.short_description = testField;
current.update();
If my answer was helpful, or solved your issue, please mark it as Helpful / Correct.
Thank you,
Cody Smith

Andrew122
Mega Expert

I probably should have clarified a bit more.

My record producer has a field (u_test) that was created on the Record Producer itself and is not linked to any table in particular.  When the Record Producer is submitted, I need to take the value from the u_test field and insert it into a different table than the one the Record Producer is writing to (We'll call table A).  For this, I know I can use a Glide Record.  The table that u_test (We'll call table B) is writing to has a reference to Table A (the Number field).  I need to have u_test write to a record on Table B that is referenced to the record created by the Record Producer on Table A.  Part of the problem lies in how the Number field doesn't get created until after the Record Producer is submitted (hence why I need an After Business Rule).