Loading variable choices when loading variables using transform maps

Tariq Alshara
Tera Expert

Dear team, I hope all is well!

 

I am working on a requirement to load data related to a certain catalog item onto the platform, the data is essentially variables relating to this catalog item as well as the choices for all the variables of the type (Select box).

 

I have successfully managed to load the variables against their catalog item using a transform map but I am facing the challenge of being unable to load the choices against their respective variables

 

I would like to avoid the method of loading the choices in a second transform map that comes after loading the variables, I would highly prefer that the variables as well as the choices are loaded in the same transform map/action

 

Any ideas on how I could implement that?

5 REPLIES 5

Ahmmed Ali
Mega Sage

Hello @Tariq Alshara 

 

One way is you can create an onAfter script on transform map. Check if the variable is of type select box and then write script to add choice values (using GlideRecord on question_choice table). 

 

Although, the second transform map approach is much simpler I guess.

 

Thank you,

Ali

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

Hello @Ahmmed Ali, thanks for the response!

 

Do you mind sharing your thoughts on how I can grab the choices if they are sitting in an Excel sheet?

 

I have the variables listed in an excel sheet with their choices against them, how would you script it?

VC EG.png

Hello @Tariq Alshara 

 

One way is you can add choices column in your catalog variables excel sheet, but do not map that field to target field in transform map. Now in transform script, you can read the choice values using source.FIELD_NAME and then write script to create records in question_choice table.

 

As for script part, below is example: please validate all field names

 

var choices = source.getValue("YOUR_CHOICE_FIELD_NAME_IN_IMPORT_SET");

 

var choicesArray = choices.split("\n");

for (var i=0; i< choicesArray.length; i++){

var grChoice = new GlideRecord("question_choice");

grChoice.initialize();

grChoice.question = target.getValue("sys_id");

grChoice.text = choicesArray[i];

grChoice.value = choicesArray[i];

grChoice.insert();

}

 

Thank you,

Ali

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

Pratik Malviya
Tera Guru

Hi @Tariq Alshara ,

 

For choice field which are creating new choices, you need to make choice action as ignore for that fields.
ex.

 

PratikMalviya_3-1666179801404.png

 

Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Thanks,
Pratik Malviya