Discussions

Expand all | Collapse all

Javascript Pop-Up which executes API=EditRecord when "OK" Selected

  • 1.  Javascript Pop-Up which executes API=EditRecord when "OK" Selected

    Posted 09-17-2020 17:27
    Edited by Jake R 09-17-2020 17:28

    Hi there, 

    I have a Formula-URL button that, if pressed, checks a box on the same record.  This triggers an email to a large number of 'Partners'. 

    var text URL=URLRoot() & "db/" & Dbid() & "?act=API_EditRecord"& "&rid=" & URLEncode ([Record ID#])& "&_fid_441=1" & "&apptoken=" & "MyAppToken"; "javascript:" &"$.get('" & $URL & "',function(){" &"location.reload(true);" &"});" & "void(0);"



    Its occured to me that if this button was pressed in error it could cause some serious damage.  So I want to add a pop-up message.  If the user presses 'Cancel', it should abort.  If 'Okay' it would check the box similar to the URL button above.

    So I tried this, 

    var text emailvar = URLRoot() & URLRoot() & "db/" & Dbid() &"?act=API_EditRecord&rid="&URLEncode ([Record ID#]) & "&_fid_441=1" &"&apptoken=MyAppToken";

    var text noemailvar = URLRoot() & URLRoot() & "db/" & Dbid() &"?act=API_EditRecord&rid="&URLEncode ([Record ID#]) & "&_fid_441=0" &"&apptoken=MyAppToken";

    var text rdr = URLRoot() & "db/" & Dbid() &"?a=dr&rid="&URLEncode ([Record ID#]) &"&apptoken=MyAppToken";

    "<a style='width: 150px;border-color:black; text-decoration: none; background:#3761a2;color:white;' class='btn btn-sm btn-primary' href='#'" & "onclick= \"return confirm('Would you like to email all CPs? If Yes - click OK, otherwise Cancel')" & "?window.location.replace('" & $emailvar & "&rdr=" & URLEncode($rdr) & "'):" & "window.location.replace('" & $noemailvar & "&rdr=" & URLEncode($rdr) & "');\"" & ">Open RFP</a>"


    When I use this code, the pop-up messages works as expected, but when I select an option (OK/Cancel) I end up with a runtime error:

    Server Error in '/' Application.


    Runtime Error

    Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.

    Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".

    <!-- Web.Config Configuration File -->
    
    <configuration>
        <system.web>
            <customErrors mode="Off"/>
        </system.web>
    </configuration>


    Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customErrors> configuration tag to point to a custom error page URL.

    <!-- Web.Config Configuration File -->
    
    <configuration>
        <system.web>
            <customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
        </system.web>
    </configuration>


    I'd love to fix this, but honestly, any approach that gets the job done would be amazing.


    Thanks,
    Jake



    ------------------------------
    Jake R
    ------------------------------


  • 2.  RE: Javascript Pop-Up which executes API=EditRecord when "OK" Selected

    Posted 09-17-2020 20:51
    I'm still trying to find other ways to do this, but it actually works.  The trick is you need to not specify the wrong table and/or app token.

    ------------------------------
    Jake R
    ------------------------------



  • 3.  RE: Javascript Pop-Up which executes API=EditRecord when "OK" Selected

    Posted 09-18-2020 13:04
    If I am understanding this right then it sounds like you could have that button take the user to another form that had a warning message plus 2 buttons one for cancelling and returning to where they were(other form, same record) and a button that sends the email(checks the checkbox) and then again returns them to the previous form. That would be the simplest way I think if you wanted to avoid JavaScript.


  • 4.  RE: Javascript Pop-Up which executes API=EditRecord when "OK" Selected

    Posted 09-18-2020 13:31
    Yes, you understood correctly and I agree the method you laid out is the simplest.  Ultimately the button was a better option (once I got it to work) because it didn't require managing extra forms or fields.

    ------------------------------
    Jake R
    ------------------------------