how to append the drop down field values?

Are Kaveri
Tera Contributor

Hello ,

 

I was working on a custom form.

there is a checkbox field on Representative table called validFlag = Boolean

there is Employee table in that we are having Frequent flag (string with drop down values Yes/No)= validFlag(representative table field) + grade (present on Employee table)

 

Before we use to copy validFlag (true/false)= Frequent flag (Yes/No)

we have before update Business rule

var gr = new GlideRecord('representative');
    gr.addQuery('sys_id', current.representative);
    gr.query();
    if (gr.next()) {
        if (gr.validflag == true) {
            current.setValue('frequentflag', 'yes');//Now Frequent flag = validFlag + Grade
        } else {
            current.setValue('frequentflag', 'no');
        }

    }
    

How to append validFlag and Grade and set to Frequent flag?

1 ACCEPTED SOLUTION

sunil maddheshi
Tera Guru

@Are Kaveri 

Try to concatenate the validFlag (converted to "Yes"/"No") with the Grade field value, please try with below script:

var gr = new GlideRecord('representative');
gr.addQuery('sys_id', current.representative);
gr.query();
if (gr.next()) {
    var validFlagValue = gr.validflag ? 'Yes' : 'No'; // Convert boolean to Yes/No
    var gradeValue = current.grade || ''; // Ensure grade is not null

    var frequentFlagValue = validFlagValue + ' ' + gradeValue; // Append values

    current.setValue('frequentflag', frequentFlagValue.trim()); // Remove any trailing spaces
}

Please mark correct/helpful if this helps you!

View solution in original post

7 REPLIES 7

sunil maddheshi
Tera Guru

@Are Kaveri 

Try to concatenate the validFlag (converted to "Yes"/"No") with the Grade field value, please try with below script:

var gr = new GlideRecord('representative');
gr.addQuery('sys_id', current.representative);
gr.query();
if (gr.next()) {
    var validFlagValue = gr.validflag ? 'Yes' : 'No'; // Convert boolean to Yes/No
    var gradeValue = current.grade || ''; // Ensure grade is not null

    var frequentFlagValue = validFlagValue + ' ' + gradeValue; // Append values

    current.setValue('frequentflag', frequentFlagValue.trim()); // Remove any trailing spaces
}

Please mark correct/helpful if this helps you!

Ankur Bawiskar
Tera Patron
Tera Patron

@Are Kaveri 

try this. I assume your business rule runs Before

var grRep = new GlideRecord('representative');
grRep.addQuery('sys_id', current.representative);
grRep.query();
if (grRep.next()) {
    var validFlag = grRep.validflag;
    var grade = current.grade; // Assuming 'grade' is a field on the Employee table

    var frequentFlagValue = (validFlag ? 'yes' : 'no') + ' ' + grade;
    current.setValue('frequentflag', frequentFlagValue);
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Ankur Bawiskar
Tera Patron
Tera Patron

@Are Kaveri 

your frequent flag field is true/false

your grade field is of what type?

what's your exact business requirement?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Thank you for response @Ankur Bawiskar 

 

validFlag = Boolen (True/False)

Frequentflag = String (drop down Yes/No)

Grade = Integer

 

here my requirement is 

Frequent Flag should represent validFlag (true/false to Yes/No)+ Grade.

lets say validFlag = true Grade = 10

it should show in Frequent flag = Yes 10

show Frequent flag with both field values