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.
12 REPLIES 12

Ankur Bawiskar
Tera Patron
Tera Patron

@klavan32 

I believe you are writing that in the inline script section of that field

try this

/*
**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.toString();
var fte = 'full_time_employee';
var con = 'contractor';
var ctg = 'contingent';
if(empType == "Employee"){
    return fte;
}else if(empType == "Contractor"){
    return con;
}else if(empType == "Contingent"){
    return ctg;
}
}

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

klavan32
Tera Contributor

Hi @Ankur Bawiskar  Thank for the reply.

 

Tried that way as well, but still its returning empty value in logs

@klavan32 

please share the logs and screenshot of the field script

the field where you are writing is choice with these values

full_time_employee,contractor and contingent

what came here?

var empType = fd_data._1__get_employee_data__snaplogic.employee_type.toString();
var fte = 'full_time_employee';
var con = 'contractor';
var ctg = 'contingent';
gs.info('employee type' + empType); //what came here in log
if(empType == "Employee"){
    return fte;
}else if(empType == "Contractor"){
    return con;
}else if(empType == "Contingent"){
    return ctg;
}
}

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

Amit Verma
Kilo Patron
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


Please mark this response as correct and helpful if it assisted you with your question.