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

Where will use the onChoiceCreate transform map script.

Rahul Kumar8
Tera Contributor

Hi all

Where will we use onChoiceCreate transform map script.

Give me one example

4 REPLIES 4

Harshal Aditya
Mega Sage

Hi Rahul,

One such example is - 

There a choice type field and you want that when a new choice is inserted then a record in a remote table is created. To accomplish the same you need to write a on choice create script.

Regards

Varsha21
Giga Guru

Hi Rahul,

 

When: The onChoiceCreate event script is processed at the start of a choice value creation, before the new choice value is created.

Import Set JS objects available to be referenced and their context in the onChoiceCreate event
Import Set JS objectTypeContext in the onChoiceCreate import set event
sourceGlideRecordThe row of the source table that is currently being processed.
targetGlideRecordThe row of the target table that is currently being processed.
mapGlideTransformMapRead-only information about the current transform map record.
logFunctionThe log object for the current import run. For example, log.info(...), log.warn(...), log.error(...).
actionStringAction returns a value of either "insert" or "update" indicating whether the current target row is about to be created or updated.
nameStringEvaluates to the field name of the target record for which a choice value is about to be created.
valueStringEvaluates to the display value from the source record for which a choice is about to be created.
ignoreBooleanWhen set to true, ignores the creation of a choice value.
errorBooleanWhen set to true, rejects the entire transformation row, no data is saved for this row.

Example:

//Create an event
var e = new GlideEvent("myimport_ChoiceCreate", action, value, "");
e.insert();

for more detail please go through link

https://docs.servicenow.com/bundle/jakarta-platform-administration/page/script/server-scripting/refe...


Thanks

Ragini Kukade
Kilo Guru

Hi,

ON CHOICE CREATE

This gets executed when a new choice is added on the transform. This transform script is triggered before the choice value is created in case there's any preparation, clean-up, preconditions, etc... for the new choice to properly exist.

Variables: source, target, map, log, action, name, value, ignore, error

 

Summary: onChoiceCreate runs before a new choice is created on a choice field. Since this script runs when a choice is created, “create” has to be selected as the choice action for that field map. If it is not selected, the script will not run. Because onChoiceCreate is a before action, only the source table record has set values. Similar to onForeignInsert, the onChoiceCreate script can take additional action when a new choice is created on a field.

 

Mark it as correct/helpful,if it helps.

Regards,

Ragini

Rahul Kumar17
Tera Guru
Hi Only Data import time. Incident from is on the State field. If I want to add some value to this field then we can write OnChoiceCreate Transformer script.
If my response helped please mark it correct and close the thread.

Thanks,
Rahul Kumar