Hello,
I would like create multiple buttons that call a business process. Due to the number of buttons in my page, I would like to create a single button click method. This method would receive a parameter that would tell it which button was called. The parameter would then determine which field would be read.
My button method should look something like this:
onButtonClick: function(clickedButton){ var recordId = this.get("Id"); var readField = "Error"; //This value should change later, will show error otherwise switch(clickedButton){ case "Button1": readField = this.get("Field1"); break; case "Button2": readField = this.get("Field2"); break; /*More Cases . . . */ default: console.log(readField); break; } var config = { sysProcessName: "UsrBpToCall", parameters: { CurrentRecordId: recordId, ReadField: readField, } }; ProcessModuleUtilities.executeProcess(config); }
I assume the parameter would appear in the diff section, but I do not know how to implement this functionality.
I appreciate your help!
Kind Regards,
Firas
Like
Hello Firas,
If you add a tag to each button it will get passed as the fourth parameter to the click handler.
For example:
{ "operation": "insert", "parentName": "Detail", "propertyName": "tools", "name": "MyButton1", "values": { "itemType": Terrasoft.ViewItemType.BUTTON, "caption": "Send selected invoice", "click": {"bindTo": "onMyButtonClick"}, "tag": "MyButton1" } }
Then you can retrieve the tag in the click function handler like this:
onMyButtonClick: function(p1, p2, p3, tag) { console.log(tag); }
Ryan
Hello Firas,
If you add a tag to each button it will get passed as the fourth parameter to the click handler.
For example:
{ "operation": "insert", "parentName": "Detail", "propertyName": "tools", "name": "MyButton1", "values": { "itemType": Terrasoft.ViewItemType.BUTTON, "caption": "Send selected invoice", "click": {"bindTo": "onMyButtonClick"}, "tag": "MyButton1" } }
Then you can retrieve the tag in the click function handler like this:
onMyButtonClick: function(p1, p2, p3, tag) { console.log(tag); }
Ryan
Ryan Farley,
the solution works perfectly. Thank you.
I have a follow-up question if you do not mind. Does the tag being passed as the fourth argument mean that button click methods can take up to 4 arguments? If that is the case how can one proceed if they were to pass more than one argument and populate p1 through p3?
Thank you again, your Community responses and articles have been very helpful.
Firas
Hello,
Not sure about passing 4 arguments to the click event, I've been using the tag property only to pass the parameter needed. In your case you can bind the click-handler method to several buttons and specify different tags for it so the click-handler method could understand what to do according to the button tag.