The CreatorCon Call for Content is officially open! Get started here.

How do I target drop down menu values in a table?

Matthew13
Mega Contributor

Hi all,

I am trying to write a server-side script that will run when I am importing an excel sheet. In my import, I have a column listed as, "Status" that when imported hits on a drop down menu which has various values as well.

I could not find any documentation or other questions that could point me to the right direction. I am trying to target the dropdown menu where if my import value hits a certain condition.

answer = (function transformEntry(source) {
    if (source.u_importValueField != "In Use") {
        
// do something here that targets my drop down menu's value to something else

})(source);

At first I thought "g_form.setValue()" would be the answer, but it only works for client side.

Anybody have any ideas?

2 REPLIES 2

Anil Lande
Kilo Patron

Hi,

You have to map label with backend value in your script:

for example If status in Excel column is 'In Use' and in ServiceNow table the value of dropdown is 'in_use' then use below logic:

answer = (function transformEntry(source) {
    if (source.u_importValueField == "In Use") {
return ='in_use';
}else if(source.u_importValueField == 'In Stock'){
return 'in_stock';
}else{
retrn 'default_value_as_per_your_configuration';
}
        
// do something here that targets my drop down menu's value to something else

})(source);

 

Thanks,

Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Thank you for the reply Anil, but unfortunately this does not work. 

In my table on ServiceNow I have a column labeled as 'State' (aligns with my excel sheet's "Status" field) which comes out of the box for ServiceNow. It is defaulted to use, "In Use" and with it, has a few other options in the drop down such as: "retired", "in stock", "in transit", "on order", etc.

When importing my excel sheet, there are some values that are not "In Use" so I want it to be reflected when it goes through the transform map and onto the table. 

I used a similar code to what you replied with, but all the values are still defaulted to, "In Use."

answer = (function transformEntry(source) {

    if (source.u_status !== "In Use") {
        return 'retired';
    } else {
	return 'in_use';
	}
})(source);