BUTTON_OnClick two part question

 15 Replies
 0 Subscribed to this topic
 12 Subscribed to this forum
Sort:
Author
Messages
brihyn
Veteran Member Send Private Message
Posts: 95
Veteran Member
Having trouble thinking this through today...I'm sure I'm doing something dumb, but I'm not seeing it. I have a button on a couple of forms that brings up a search window of related scanned images Script looks like this: function BUTTON_OnClick(button) {  if (button == "push12")  {   var VenNum = lawForm.getFormValue("text2");   VenNum = trim(VenNum);   var ImageUrl = "/search/vendorsearch.asp?query=%23filename%3D%22" + VenNum + "_*.*%22";   window.open(ImageUrl);  } // return true; } problem 1- The new image button works great, but just found out that my script is keeping any of the default buttons from working. Clicking on them, nothing happens. How do i map the one button in the script without affecting other buttons? Second, possibly related, possibly not- When I un-remark the return true line, clicking on the button will still cause my search to work, but then i get an ios error stating, in effect, Missing required parameter: _TKN. Any ideas? Thanks as always!
David Williams
Veteran Member Send Private Message
Posts: 1127
Veteran Member
Change your line to if (button != "push12") return true; { so all of the other buttons will process as normal and your script will only run when the button == push12. After doing that, see if your other error is also resolved and if not report back.
David Williams
brihyn
Veteran Member Send Private Message
Posts: 95
Veteran Member
With if (button != "push12") return true; { The other buttons all work, but clicking on the button 12, I get the com.lawson.ios.agent.AgentException: Missing required parameter: _TKN. error, and my popup never shows.
Deleted User
New Member Send Private Message
Posts: 0
New Member
You don't have to check if the button is not push12, if you uncomment the return true that will do the same thing. What version of DS are you on?  the BUTTON_OnClick should pass (id, row)  with id being "push12"
Michael Thedford
Advanced Member Send Private Message
Posts: 19
Advanced Member
Not sure what the button test (if statement) portion of the function is for, since we do not know how you have your button defined. From what it looks like, all you need is a function called GetImage or anything of your choosing. function GetImage() { var VenNum = lawForm.getFormValue("text2"); if (VenNum == '') ( alert ("Cannot Display image without a valid Vendor Number value on the form."); return false; ) VenNum = trim(VenNum); var ImageUrl = "/search/vendorsearch.asp?query=%23filename%3D%22" + VenNum + "_*.*%22"; window.open(ImageUrl); return true; } Define your button Action as: Function, then select the GetImage function from the function name list. When that button is clicked, it will only run that fuction and will not affect any other buttons. Hope that helps
brihyn
Veteran Member Send Private Message
Posts: 95
Veteran Member
Define your button Action as: Function, then select the GetImage function from the function name list. When that button is clicked, it will only run that fuction and will not affect any other buttons. Hope that helps
I think this is getting closer. I messed a little with the function option on the button. I selected Function now, and there's no options to pick from. I typed in GetImage but preview of the form, the button isn't doing a thing now. Am I missing a step to make the function a listed function?
Deleted User
New Member Send Private Message
Posts: 0
New Member
You have () instead of {} within the statement of the  first if statement there, that would cause the function not to be evaluated and thus not show as available to select from.
brihyn
Veteran Member Send Private Message
Posts: 95
Veteran Member
You have () instead of {} within the statement of the first if statement there, that would cause the function not to be evaluated and thus not show as available to select from.
good catch, but it actually wouldn't let me apply the script with the ()s. Already had it switched to {} and unfortunately still doesn't show in a list of functions, and the button doesn't do a thing.
David Williams
Veteran Member Send Private Message
Posts: 1127
Veteran Member
Please attach your script in a text file to this forum so we can review it.
David Williams
brihyn
Veteran Member Send Private Message
Posts: 95
Veteran Member
here's everything I have on my scripts page (for reference) function trim(str) { return str.replace(/^\s+|\s+$/g,""); } function GetImage() { var VenNum = lawForm.getFormValue("text2"); if (VenNum == '') { alert ("Cannot Display image without a valid Vendor Number value on the form."); return false; } VenNum = trim(VenNum); var ImageUrl = "/search/vendorsearch.asp?query=%23filename%3D%22" + VenNum + "_*.*%22"; window.open(ImageUrl); return true; } On the button, I have Function selected, and GetImage in the space.
brihyn
Veteran Member Send Private Message
Posts: 95
Veteran Member
txt file attached
Attachments
Michael Thedford
Advanced Member Send Private Message
Posts: 19
Advanced Member
After making the changes on the Script page, are you then going to Edit / Apply Changes - to actually apply the script changes you made? After that, it should be a valid fuction to select from when you select your custom button, select Action from it's properties, select Function as the Action type, then all fuctions on the script page should be listed to select from. Also, put an alert after the "VenNum = trim(VenNum);" to see what that value is at that point.
Deleted User
New Member Send Private Message
Posts: 0
New Member
It sounds stupid, but try deleting any extra spaces you have at the end of the function line.  I have found that works before.
Michael Thedford
Advanced Member Send Private Message
Posts: 19
Advanced Member
It may also want a CR/LF after the last "}" in the function. Sorry about the "()" instead of the "{}"'s earlier in the thread. Darn high resolution settings and small font...
Deleted User
New Member Send Private Message
Posts: 0
New Member
Even if you don't see it listed, you should still be able to use it. Just type GetImage() in the line on top, this has worked for me in the past too when functions don't display in the list.
brihyn
Veteran Member Send Private Message
Posts: 95
Veteran Member
wow, gotta love issues like this. Got rid of all of the spaces and extra carriage returns and sure enough, GetImage() shows up now, and the script works like a charm. Thanks everyone!