Set value of list field type

trmiller
Kilo Expert

I have a list field type (u_year) inside table sn_compliance_policy_statement. My choices in that list field are years, such as 2016, 2017, 2018, etc. I am trying to query all records with the active field set to true and then set the value of the u_year list field to 2017.

Here is my field to avoid confusion to show the specific type of field (list vs list collector, etc.). The years are stored on the sys_choice table with the table as sn_compliance_policy_statement, element is u_year, and value is 2016, 2017, etc. I think where I am getting stuck is trying to pull in both the active records and the choice list value at the same time. Thanks for any assistance.

find_real_file.png

1 ACCEPTED SOLUTION

Kamal17
Kilo Sage

Hi Miller,



My understanding is that you are trying to write a script to query active records from 'sn_compliance_policy_statement' table and update the field 'u_year' in each of those record with the value 2017. If that's the case then below script might be helpful,



Script:


var gr = new GlideRecord('sn_compliance_policy_statement');


gr.addQuery('active',true);


gr.query();


while(gr.next()){


gr.u_year = '2017';


gr.update();


}



You can execute the above code in background script to update the records.



-Udhay


Please Hit like, Helpful or Correct depending on the impact of the response


View solution in original post

5 REPLIES 5

Gurpreet07
Mega Sage

Hi Thomas,



Can you please paste your code in here.


Here are a couple similar ones, slight variances I tried. Neither one has been successful.



var policy = new GlideRecord('sn_compliance_policy_statement');


policy.addQuery('u_hitrust_policy_statement', false);


policy.query();


while (policy.next()) {


policy.u_hitrust_policy_statement = true;


policy.update();


}




var gr = new GlideRecord('sn_compliance_policy_statement');


gr.addQuery('active',true);


gr.query();


while(gr.next()){


gr.u_year = '2017';


gr.update();


}


Kamal17
Kilo Sage

Hi Miller,



My understanding is that you are trying to write a script to query active records from 'sn_compliance_policy_statement' table and update the field 'u_year' in each of those record with the value 2017. If that's the case then below script might be helpful,



Script:


var gr = new GlideRecord('sn_compliance_policy_statement');


gr.addQuery('active',true);


gr.query();


while(gr.next()){


gr.u_year = '2017';


gr.update();


}



You can execute the above code in background script to update the records.



-Udhay


Please Hit like, Helpful or Correct depending on the impact of the response


Thanks, this is similar to a script I tried before. No errors thrown, but it does not update the field. Could this be related to the field not being editable in the list? Interestingly enough, I try adding an ACL for list-edit but it never allows me to edit it via the list.



In addition to the script, I have tried setting the u_year variable to the 2017 choice SysID to jo avail.