Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

how to Map the choice variable dynamically in flow designer

klavan32
Tera Contributor

Hi All,

 

I am trying to map the choice field of a snow user profile through flow designer. we get user data through an integration and value should be mapped to field in snow user profile dynamically based on the input we receive as we have different choice values in snow end. trying with below script but it is returning empty value:

 

/*
**Access Flow/Action data using the fd_data object. Script must return a value.
**Order number is offset by +1 in Error Handling Section.
**Available options display upon pressing "." after fd_data
**example: var shortDesc = fd_data.trigger.current.short_description;
**return shortDesc;
*/
var empType = fd_data._1__get_employee_data__snaplogic.employee_type;
var fte = 'full_time_employee';
var con = 'contractor';
var ctg = 'contingent';
if (get(empType)){
if(empType == "Employee"){
    return fte;
}else if(empType == "Contractor"){
    return con;
}else if(empType == "Contingent"){
    return ctg;
}
}
 
If i am trying to map directly as one of the choice value then its mapping but through script its not working
 
Can someone please help and suggest on the same.
1 ACCEPTED SOLUTION

vermaamit16
Kilo Patron

Hi @klavan32 

 

Please check the following points:

 

1. Remove if (get(empType)) from your script.

2. What is the value being returned by employee_type variable. For that, please check the flow execution context and see the value. Compare the value being returned with your if-else logic.

3. If the empType variable is being set properly, check for the choice field values. As per your script, your choice field has values like full_time_employee etc. Please cross-verify the same.

 

Thanks and Regards

Amit Verma

Thanks and Regards
Amit Verma

View solution in original post

12 REPLIES 12

yuvarajkate
Giga Guru
/*
**Access Flow/Action data using the fd_data object. Script must return a value.
*/
var empType = fd_data._1__get_employee_data__snaplogic.employee_type;
var fte = 'full_time_employee';
var con = 'contractor';
var ctg = 'contingent';

if (empType) { // Check if empType is defined and not null
    if (empType === "Employee") {
        return fte;
    } else if (empType === "Contractor") {
        return con;
    } else if (empType === "Contingent") {
        return ctg;
    } else {
        return ''; // Return empty if no match found
    }
} else {
    return ''; // Return empty if empType is undefined or null
}

klavan32
Tera Contributor

Hi @vermaamit16  and @Ankur Bawiskar 

I am seeing this log from input context logs

klavan32_0-1737694662267.png

 

@klavan32 

 

This indicates that you have not defined the output variable employee_type in 

get_employee_data__snaplogic

 action or if you have defined the output variable, check the variable name. Use dot-walking to get the variable value while scripting.

 

Can you please share your action configurtion?

Thanks and Regards
Amit Verma

@klavan32 

it means you are not taking the value correctly

Please share complete flow steps along with screenshot

Is that flow on catalog and that is a variable?

If yes then you should use Get Catalog Variable action and then dot walk and get that variable value

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

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

klavan32
Tera Contributor

Hi @Ankur Bawiskar  here is the action details that we have configured.

script step : 

klavan32_0-1737958902770.png

outputs:

klavan32_1-1737958941263.png

As per the error, it is mentioned that employee_type in output is not defined 

klavan32_3-1737959137396.png

 

when we tested the action , we got employee_type details in output message[string] as below:

klavan32_2-1737959101797.png

 

We wanted to add this update to already exisiting configuration and mapped as same as per existing.