Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

how to set value for string field having choices using fix script

Apoorva Kadu
Tera Contributor

I want to insert a record with fiscal year field value, on form it is choice field but in backend it's a string 

tableRec = new GlideRecord('cost_plan');
tableRec.initialize();
tableRec.name = 'Test costplan4';
tableRec.task = 'ff80cc231bb3f89c2473eb19b04bcb43';
tableRec.u_fiscal_year = 'FY-22/23'; // if am giving direct choice value it is coming in blue color 

OR

tableRec.u_fiscal_year = 'af36cf62dbad9c509a88b1b239961937';  //if am giving sys_id of (FY-22/23) then sys_id is coming in the field.
tableRec.insert();

What is the correct method to insert choice from choice list 

 

5 REPLIES 5

Community Alums
Not applicable

Hello,

Since it's string field and choice is not available it will show in blue. Kindly create new choice "FY-22/23" and then try to set with this value (not sys id), it will be in black color only. 

 


Thanks
Akshay Kangankar
Please Mark āœ… Correct/helpful, if applicable,

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

please give the choice value and not the choice label or sysId

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Thanks, It's working now 

@Apoorva Kadu 

Glad to know.

Please mark my response as correct and close the thread.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader