Automate

 View Only
  • 1.  Javascript code not working properly on Save and Route

    Posted 03-07-2024 19:27

    Hi Community,

    Hoping someone has some input. We have a form where we need logic on the Save and Route button. It needs to check the entry for Currency Key and Standard Price. If Currency contains a value that does not allow decimals and if Standard Price contains a decimal it should give an error and not Save and Route. Then basically the opposite scenario should allow save and route. I have tried two different ways but both of them fail if Currency Key = USD. I click save and route and you see a blink of something but it never proceeds. Am I missing something simple? Looking forward to any suggestions.

    Ex #1:

    var Error = '';
    if ($form.getValue('/my:myFields/my:FG_Validate/my:FG_Validate_Input/my:Repeating_Content/my:Currency_Key') === 'JPY' || $form.getValue('/my:myFields/my:FG_Validate/my:FG_Validate_Input/my:Repeating_Content/my:Currency_Key') === 'COP' || $form.getValue('/my:myFields/my:FG_Validate/my:FG_Validate_Input/my:Repeating_Content/my:Currency_Key') === 'KRW' || $form.getValue('/my:myFields/my:FG_Validate/my:FG_Validate_Input/my:Repeating_Content/my:Currency_Key') === 'CLP')
    if ($form.getValue('/my:myFields/my:FG_Validate/my:FG_Validate_Input/my:Repeating_Content/my:Standard_price').toString().match(/\./) !== null){
        
    $form.showMessage('Currency Key does not allow decimals for Standard Price', 'Error');
    Error = 1;
    }
    if(Error == ''){
    if ($form.getValue('/my:myFields/my:FG_Validate/my:FG_Validate_Input/my:Repeating_Content/my:Currency_Key') != 'JPY' || $form.getValue('/my:myFields/my:FG_Validate/my:FG_Validate_Input/my:Repeating_Content/my:Currency_Key') != 'COP' || $form.getValue('/my:myFields/my:FG_Validate/my:FG_Validate_Input/my:Repeating_Content/my:Currency_Key') != 'KRW' || $form.getValue('/my:myFields/my:FG_Validate/my:FG_Validate_Input/my:Repeating_Content/my:Currency_Key') != 'CLP')
    if ($form.getValue('/my:myFields/my:FG_Validate/my:FG_Validate_Input/my:Repeating_Content/my:Standard_price').toString().match(/\./) === null){
        
        SVFormDoSetActionsAndSubmit(2,'TODO_ButtonId');
    }
    }
    Ex #2:
    if ($form.getValue('/my:myFields/my:ING_Validate_Extend/my:ING_Validate_Extend_Input/my:Repeating_Content/my:Currency_Key_2').toString().match(/JPY/) !== null || $form.getValue('/my:myFields/my:ING_Validate_Extend/my:ING_Validate_Extend_Input/my:Repeating_Content/my:Currency_Key_2').toString().match(/COP/) !== null || $form.getValue('/my:myFields/my:ING_Validate_Extend/my:ING_Validate_Extend_Input/my:Repeating_Content/my:Currency_Key_2').toString().match(/KRW/) !== null && $form.getValue('/my:myFields/my:ING_Validate_Extend/my:ING_Validate_Extend_Input/my:Repeating_Content/my:Standard_price_2').toString().match(/\./) !== null){
    $form.showMessage('Currency Key does not allow decimals for Standard Price', 'Standard Price Error');
    } else {
        SVFormDoSetActionsAndSubmit(2,'TODO_ButtonId');
    }


    ------------------------------
    Shelby Murrell
    SAP Functional Lead (Winshuttle Evolve)
    MONSTER ENERGY
    [USA]
    ------------------------------


  • 2.  RE: Javascript code not working properly on Save and Route

    Posted 03-07-2024 20:01

    30 min after I posted this I ended up figuring out the code and it worked. In case it may help someone else. I was missing an else if.

    if ($form.getValue('/my:myFields/my:FG_Validate/my:FG_Validate_Input/my:Repeating_Content/my:Currency_Key') === 'JPY' || $form.getValue('/my:myFields/my:FG_Validate/my:FG_Validate_Input/my:Repeating_Content/my:Currency_Key') === 'COP' || $form.getValue('/my:myFields/my:FG_Validate/my:FG_Validate_Input/my:Repeating_Content/my:Currency_Key') === 'KRW' || $form.getValue('/my:myFields/my:FG_Validate/my:FG_Validate_Input/my:Repeating_Content/my:Currency_Key') === 'CLP')
    if ($form.getValue('/my:myFields/my:FG_Validate/my:FG_Validate_Input/my:Repeating_Content/my:Standard_price').toString().match(/\./) !== null){
        
    $form.showMessage('Currency Key does not allow decimals for Standard Price', 'Error');
    } else {
        SVFormDoSetActionsAndSubmit(2,'TODO_ButtonId');
    } else if ($form.getValue('/my:myFields/my:FG_Validate/my:FG_Validate_Input/my:Repeating_Content/my:Currency_Key') != 'JPY' || $form.getValue('/my:myFields/my:FG_Validate/my:FG_Validate_Input/my:Repeating_Content/my:Currency_Key') != 'COP' || $form.getValue('/my:myFields/my:FG_Validate/my:FG_Validate_Input/my:Repeating_Content/my:Currency_Key') != 'KRW' || $form.getValue('/my:myFields/my:FG_Validate/my:FG_Validate_Input/my:Repeating_Content/my:Currency_Key') != 'CLP')
    if ($form.getValue('/my:myFields/my:FG_Validate/my:FG_Validate_Input/my:Repeating_Content/my:Standard_price').toString().match(/\./) === null || $form.getValue('/my:myFields/my:FG_Validate/my:FG_Validate_Input/my:Repeating_Content/my:Standard_price').toString().match(/\./) != null){
        
        SVFormDoSetActionsAndSubmit(2,'TODO_ButtonId');
    }


    ------------------------------
    Shelby Murrell
    SAP Winshuttle Analyst
    MONSTER ENERGY
    [USA]
    ------------------------------



  • 3.  RE: Javascript code not working properly on Save and Route

    Employee
    Posted 03-12-2024 09:55
    Edited by Sigrid Kok 03-12-2024 09:56

    Hi @Shelby Murrell

    Thanks for posting the fix :)

    If you use custom form buttons, turning off the standard ones, you might be able to do something like that in a regular rule.  Just a thought in case you want to consider it.  It's on the workflow tab - search for buttons and you will see the Form Default Buttons, which you specify which views, if any, have the default buttons - with the default being All Views.  You can change it to only have certain views use the default buttons or no views, which is what I usually do.  Then I can add rules and also change placement.

    Then on the approve/submit/complete button you add, you can have rules that check for various things, like did they validate or post or the rules you mentioned for currency and decimals.

    Best Regards,

    Sigrid



    ------------------------------
    Sigrid Kok
    Precisely Software Inc.
    ------------------------------



  • 4.  RE: Javascript code not working properly on Save and Route

    Posted 03-12-2024 15:18

    Thanks Sigrid! We actually do have the default buttons set to "no views". This is a custom rule I put on the "submit" button we have :)



    ------------------------------
    Shelby Murrell
    SAP Winshuttle Analyst
    MONSTER ENERGY
    [USA]
    ------------------------------