Map checkbox to list field using record producer

brostoff17
Tera Contributor

I have a series of checkbox variables that I want to map to a list field on the table.   Checking the checkbox just returns "true" or "false", so I cant map the fields.   Has anyone done this using an onSubmit script to map the fields?

1 ACCEPTED SOLUTION

I am guessing that your variable names are direct and together. If that is the case, you need to indicate that they are part of the producer form by adding producer. in front of the variable name:



      var wArray = [];


      if (producer.direct == 'true') {


          wArray.push('241aee49db72f2409502f6e9af961944');


      }


      if (producer.together == 'true') {


              wArray.push('562a6e49db72f2409502f6e9af9619d4');


      }


      current.u_product_line = wArray.toString();


View solution in original post

10 REPLIES 10

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Josh,



Did you mean mapping checkbox field to list type field? Can you please give more details. Thank you.


Hi Pradeep,



Yes, that is what I meant.




Capture2.PNG



(Record Producer)



Capture.PNG


(Form on table)


SanjivMeher
Kilo Patron
Kilo Patron

You can write a record producer script.


There you can set current.your_list_field = 'sys id of those values in comma seaparated values';



find_real_file.png



Please mark this response as correct or helpful if it assisted you with your question.

ccajohnson
Kilo Sage

The easiest thing to do is to have an array that is used to populate the list field. Since list fields are just an array of sys_id, you will need to capture the sys_id of the corresponding record. Here is a simple example using a record producer script on the incident table. I created two Checkbox Variables (watch_me, watch_mgr). Depending upon if they are checked will determine what to look up. Since we are adding to the watch list, I just need to capture the sys_id of either myself, or my manager. Depending upon how to get at your values within your list will determine how you alter the code.



var wArray = [];


var usrObj = gs.getUser();


current.caller_id = usrObj.getID();


if (producer.watch_me == 'true') {


  wArray.push(usrObj.getID());


}


if (producer.watch_mgr == 'true') {


  wArray.push(usrObj.getManagerID().toString());


}


current.watch_list = wArray.toString();