- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2019 09:01 AM
Hello~
I have a quick question, I ran across this transform script, and there is this part that I don't understand:
action === "update"
Can someone please explain it to me? mainly why is there a check for update, does that mean that if it is not update, then the code inside the transformRow function will not be executed?
(function transformRow(source, target, map, log, isUpdate) {
......
})(source, target, map, log, action==="update");
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2019 09:33 AM
To explain this, we first need to know self-executable functions in Javascript. The parameter passing in a self-executable function is defined in the bottom portion of it.
(function(param1, param2, param3) {
if(param3){//True
gs.log(param1);//Eggs
gs.log(param2);//Cheese
}
})("eggs","cheese",true);
The script you found, is setting isUpdate to true based on the action parameter. it doesn't mean the script won't execute if it's not an update operation, the answer really depends on how the script is defined inside the function.
By the way, where did you find this code? and can you post the function body?
Thank you,
Aman Gurram
Please mark the answer correct/helpful if applicable!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2019 09:12 AM
If I had to guess, I would guess that the isUpdate argument is a boolean and being assigned the value of the expression action==="update". It's a clever, if somewhat opaque way of passing in a flag telling the function whether or not the current action is an update or some other action -- "insert" or "delete" for example.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2019 09:33 AM
To explain this, we first need to know self-executable functions in Javascript. The parameter passing in a self-executable function is defined in the bottom portion of it.
(function(param1, param2, param3) {
if(param3){//True
gs.log(param1);//Eggs
gs.log(param2);//Cheese
}
})("eggs","cheese",true);
The script you found, is setting isUpdate to true based on the action parameter. it doesn't mean the script won't execute if it's not an update operation, the answer really depends on how the script is defined inside the function.
By the way, where did you find this code? and can you post the function body?
Thank you,
Aman Gurram
Please mark the answer correct/helpful if applicable!