ui action

carlosromero
Giga Contributor

i have created a field (checkbox) on change form and its doing the following when is set to true is taking away the request apporval action both the one from the top of the form and the one at the bottom of the form using this code

client script

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

    if (isLoading|| newValue === '') {

          return;

    }

if (g_form.getValue('u_vendor_change') == 'true' ) {

document.querySelectorAll("#state_model_request_assess_approval")[0].hide();

        document.querySelectorAll("#state_model_request_assess_approval")[1].hide();

}

   

else {

document.querySelectorAll("#state_model_request_assess_approval")[0].show();

        document.querySelectorAll("#state_model_request_assess_approval")[1].show();

       

    }

}

when is click save is saving the changes, however if i want to set to false again the checkbox is displaying an error message

find_real_file.png

does anyone know what i am doing wrong

1 ACCEPTED SOLUTION

Here is a try/catch code with your script :


try{


  if (g_form.getValue('u_vendor_change') == 'true' ) {


            document.querySelectorAll("#state_model_request_assess_approval")[0].hide();


            document.querySelectorAll("#state_model_request_assess_approval")[1].hide();


  }


  else {


            document.querySelectorAll("#state_model_request_assess_approval")[0].show();


            document.querySelectorAll("#state_model_request_assess_approval")[1].show();


  }


  }catch(error) {


            console.log("Error on vendor change script "+error);


  }


View solution in original post

13 REPLIES 13

i know what is happening but not sure how to tackle the problem. the code i have above is looking for the UI Action request approval if this one is presented on the form and my checkbox field is checked the request approval is removed. however if i save the form obvioulsy the request approval is not there anymore so if i uncheck the field this one it will still look for the name of the request approval and thats why is generating the issue i guess.



what i would have to do is to enclose my code in some kind a IF saying fiend the ui action reques approval if is found do what code says and if its not found dont do nothing.





but im not sure how to   put this condition


something like this however this is not working



function onChange(control, oldValue, newValue, isLoading, isTemplate) {


if (isLoading|| newValue === '') {


return;


}



if (g_form.getElement(state_model_request_assess_approval)) // find ui action request for approval


{



if (g_form.getValue('u_vendor_change') == 'true' ) {



document.querySelectorAll("#state_model_request_assess_approval")[0].hide();


document.querySelectorAll("#state_model_request_assess_approval")[1].hide();



}


}



else {


if (g_form.getValue('u_vendor_change') == 'false' ) {


// document.querySelectorAll("#state_model_request_assess_approval")[0].show();


//           document.querySelectorAll("#state_model_request_assess_approval")[1].show();



}}


}


any help


In that case, you should check that if the element is present in the page then only it should show/hide, for example :


if(jQuery("[id=state_model_request_assess_approval]").length == 2) {


      console.log("UI action found");


      jQuery("[id=state_model_request_assess_approval]").hide();


}


Also, this is runtime exception, you should use "try - catch"   to deal with this kind of issues.


do you know how can i add that on my code