- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2023 12:55 PM
Could you please explain below code. As it's OOB script I'm not able to understandthe script properly.
Below script is written on Transform Map script
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2023 03:39 PM
- function setMakeAndModel(): This is a function definition in the Transform Map script. It is intended to set the "make" and "model" fields on a target record (usually a table) based on data from a source record (which is also a table). 
- var mm = MakeAndModelJS.fromNames(source.u_manufacturer, source.u_model, "hardware");: In this line, a JavaScript variable mm is declared. This variable is being set to the result of the MakeAndModelJS.fromNames function call. It is passing three arguments: - source.u_manufacturer: This is presumably a field from the source record that contains the manufacturer information.
- source.u_model: This is presumably a field from the source record that contains the model information.
- "hardware": This string indicates the model type, which is set as "hardware."
 
- target.model_id = mm.getModelNameSysID();: This line sets the "model_id" field on the target record to the result of the mm.getModelNameSysID() function call. 
- target.manufacturer = mm.getManufacturerSysID();: This line sets the "manufacturer" field on the target record to the result of the mm.getManufacturerSysID() function call. 
Now, let's dive into the code within the script include MakeAndModelJS.fromNames.
- MakeAndModelJS.fromNames = function(make, model, modelType): This code defines a function within the MakeAndModelJS object called fromNames. It expects three arguments: - make: The manufacturer name.
- model: The model name.
- modelType: The type of model (e.g., "hardware").
 
- var modelTable = SncMakeAndModel.determineModelTableName(modelType);: This line determines the appropriate table name based on the modelType. It uses a function called determineModelTableName in the SncMakeAndModel object to do this. The result is stored in the modelTable variable. 
- var makeAndModelJava = SncMakeAndModel.fromNames(make, model, modelTable);: This line retrieves the data from the ServiceNow instance using the SncMakeAndModel.fromNames function, passing the make, model, and modelTable as arguments. The result is stored in the makeAndModelJava variable. 
- var mm = new MakeAndModelJS(makeAndModelJava);: This line creates a new MakeAndModelJS object, which is initialized with the data retrieved from the ServiceNow instance using the makeAndModelJava object. 
- return mm;: Finally, the mm object (an instance of MakeAndModelJS) is returned from the fromNames function. 
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2023 03:39 PM
- function setMakeAndModel(): This is a function definition in the Transform Map script. It is intended to set the "make" and "model" fields on a target record (usually a table) based on data from a source record (which is also a table). 
- var mm = MakeAndModelJS.fromNames(source.u_manufacturer, source.u_model, "hardware");: In this line, a JavaScript variable mm is declared. This variable is being set to the result of the MakeAndModelJS.fromNames function call. It is passing three arguments: - source.u_manufacturer: This is presumably a field from the source record that contains the manufacturer information.
- source.u_model: This is presumably a field from the source record that contains the model information.
- "hardware": This string indicates the model type, which is set as "hardware."
 
- target.model_id = mm.getModelNameSysID();: This line sets the "model_id" field on the target record to the result of the mm.getModelNameSysID() function call. 
- target.manufacturer = mm.getManufacturerSysID();: This line sets the "manufacturer" field on the target record to the result of the mm.getManufacturerSysID() function call. 
Now, let's dive into the code within the script include MakeAndModelJS.fromNames.
- MakeAndModelJS.fromNames = function(make, model, modelType): This code defines a function within the MakeAndModelJS object called fromNames. It expects three arguments: - make: The manufacturer name.
- model: The model name.
- modelType: The type of model (e.g., "hardware").
 
- var modelTable = SncMakeAndModel.determineModelTableName(modelType);: This line determines the appropriate table name based on the modelType. It uses a function called determineModelTableName in the SncMakeAndModel object to do this. The result is stored in the modelTable variable. 
- var makeAndModelJava = SncMakeAndModel.fromNames(make, model, modelTable);: This line retrieves the data from the ServiceNow instance using the SncMakeAndModel.fromNames function, passing the make, model, and modelTable as arguments. The result is stored in the makeAndModelJava variable. 
- var mm = new MakeAndModelJS(makeAndModelJava);: This line creates a new MakeAndModelJS object, which is initialized with the data retrieved from the ServiceNow instance using the makeAndModelJava object. 
- return mm;: Finally, the mm object (an instance of MakeAndModelJS) is returned from the fromNames function. 
