Hi all,
I've been trying to search a lot of places for a solution on how to do a button placed at the "Mass Action Menu" and thus only updating multiple CHOSEN records at once. After finding no success whatsoever, I decided to just run and test whatever I can think of and finally, it worked; thanks to no easily accessible resources by Zoho ( you guys really need to improve this).
Right, to the function.
In the function you are about to write, you can edit the Arguments. Let's say for example we're dealing with the Deals module, then what you want to do is add an argument mapping to the Deal ID field. I would suggest putting the mapping value as a plural (i.e: DealIDs) because we will be dealing with multiple records most of the time.
Now, what would happen when the button is clicked when multiple records are chosen is, it would return the IDs of the Deals record like this:
1243331222221004|||1243331222221005|||1243331222221006
Why? Hell, I have no idea. But this is a string value. We have to convert this string into a list and that's simple. Simply write this line:
if(DealIDs.contains("|||") == true)
{
DealIDs = DealIDs.toList("|||");
}
else
{
DealIDs = DealIDs.toList();
}
This will change the string value to a list. And why do I do the conditional thing is because there is a possibility that only one record is chosen and in that case, there will be no "|||" in the returned value.
Then, simply do the "for each" thing, for example;
- for each DealID in DealIDs
- {
- updateStage = Map();
- updateStage.put("Stage","Closed_Won");
- updateDeal = zoho.crm.updateRecord("Deals",DealID,updateStage);
- }
- return "The deals are updated successfully";
And it should work just fine. Hope this helps. And hey, if you have a better way, please please please tell me, I'm not a programmer so my work might not be optimal.
Cheers!