uable to update field with dynamic value as it is Choice field.

srinidhi
Tera Guru

Hello Team,

 

How to update choice field dynamically, when i try to use below syntax it is creating duplicate record.

 current.setValue(FieldName, displayName);

please suggest me here Thanks.

 

 

1 ACCEPTED SOLUTION

swathisarang98
Giga Sage
Giga Sage

Hi @srinidhi ,

 

You can not directly do this through set value, try to get values from Payload if that is not at all possible then as a workaround what you can do is store the state choice label inprogress or fetch that value in a variable and query sys_choice table and add table name in query and then set the state value .

 

example;

for testing i have a randon=m string field where i set value as In Progress and in before update business rule i gliderecord to sys_ choice table and got the value for label In progress and set the state value in incident,

 

BR:

swathisarang98_0-1711451282608.png

 

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

   

    var choiceLabel = current.u_string_1;

	//gs.info('label: ' + choiceLabel);
    var gchoice = new GlideRecord('sys_choice');
    gchoice.addEncodedQuery('nameSTARTSWITHINCIDENT^element=state');
    gchoice.addQuery('label', choiceLabel); // here i have added dummy value stored in a string to check but what you can do is get the pay load value store it in a variable and use that to query
    gchoice.query();
    if (gchoice.next()) {
		//gs.info('value '+ gchoice.getValue('value'));
        current.setValue('state', gchoice.getValue('value'));
    }


})(current, previous);

 

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

View solution in original post

15 REPLIES 15

Sohail Khilji
Kilo Patron
Kilo Patron

Hi @srinidhi ,

 

Can you explain your query bit clear ?


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

Hello Sohail,

 

Through payload am storing all the values in different variables.

Am gliding to new table and creating the record with these values.

 

but for the choice field when i try to update, it's updating and making duplicate entry.

 

Make sure to set the appropriate value to your choice field. If it finds a diffrence to existing choices it will trend to create a new choice (may be duplication).

 

make sure to use techenical name of choice to set the value as example below for incident state.

 

g_form.getValue('state', '3'); // instead of inProgress use ''3''

☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

Yes Sohail, i got your point. but from the payload i will be getting the value as inProgress not 3 right.