cancel
Showing results for 
Search instead for 
Did you mean: 

Need code for validations in sybase(custom.js)?

Former Member
0 Kudos

Validations for a single screen with two button( i.e. two MBO's)? first mbo need to validate plant material storage location for second mbo  validations are need for  plant material storage location and customer??

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

We need validations for Plant(not visible in the screen) Material and customer for inventory detail screen i.e if user clicks on below buttons without giving the input it should threw error that they are required.we have an option for mandatory but the problem is customer is not mandatory for both button , it is mandatory for only one button if we give at screen designing level it reflects for both the buttons.

Thanks in advance.

midhun_vp
Active Contributor
0 Kudos

Interesting. Here you go,

Add the below code inside your custom.js

// The function customBeforeMenuItemClick you can find inside custom.js

hwc.customBeforeMenuItemClick = function(screen, menuItem) {

          

    if (screen === "Start" && menuItem === "Inventory_detail") // Here you have to give the key of your screen and the button key.

{

              var form = document.forms[screen + "Form"];

              if (form)

        {

            var cost = form.Enter_Airline_ID.value; // Enter the key of the edit box

           

        }

               if (cost==null || cost == "") //add more fields here for validation.

{

                   alert("Please enter the mandatory fields");

                   return false;

         }

    }

    return true;

};

- Midhun VP

Former Member
0 Kudos

Thanks Midhun But Already tried the above code as per our requirement mentioned below , its not working ,its not navigating to next screen nor throwing the error(validation).

function customBeforeMenuItemClick(screen, menuItem) {

if (screen === "InventorySelection" && menuItem==="InventoryOverview") {
                 var form =  document.forms[screen + "Form"];
                 if (form){
                         var Plant = form.Plant.value;
                     //var Material_m = form.Material_m.value;
                     var StorageLocation = form.StorageLocation.value;
                 //var StorageLocation = form.StorageLocation.value;
                 var flag=false;
          //var LName = form.ExpenseTracking_create_lastName_paramKey.value;

          var helpElem_Plant =document.getElementById(screen + "_Plant_help");
          var helpElem_Material =document.getElementById(screen + "_Material_help");
          var helpElem_StorageLocation =document.getElementById(screen + "_StorageLocation_help");
          if (Plant == null ||Plant == '') {
                   //form.Plant_m.style.border='1px solid red';
                   //var helpElem =document.getElementById(screenKey + "_Plant_m_help");
                           setValidationText(helpElem_Plant, "<font style='color:orange'>Please enter Plant</font>");
                   flag=true;
          }else if(Plant.length >= '5'){
                   setValidationText(helpElem_Plant, "<font style='color:orange'>Only 4 characters will allowed here</font>");
                   flag=true;
           }else

  if(!regex.test(Plant)){
                   setValidationText(helpElem_Plant, "<font style='color:orange'>Special characters not allowed here</font>");
                   flag=true;
           }else{
                  setValidationText(helpElem_Plant, "");
           }

                  setValidationText(helpElem_Material, "");

          if (StorageLocation == null ||StorageLocation == '') {
                   //form.Plant_m.style.border='1px solid red';
                   //var helpElem =document.getElementById(screenKey + "_Plant_m_help");
                           setValidationText(helpElem_StorageLocation, "<font style='color:orange'>Please enter StorageLocation</font>");
                   flag=true;
          }else if(StorageLocation.length >= '5'){
                   setValidationText(helpElem_StorageLocation, "<font style='color:orange'>Only 4 characters will allowed here</font>");
                   flag=true;
           }else if(!regex.test(StorageLocation)){
                   setValidationText(helpElem_StorageLocation, "<font style='color:orange'>Special characters not allowed here</font>");
                   flag=true;
           }else{
                  setValidationText(helpElem_StorageLocation, "");
           }
         
           if(flag){ return false; }
           }
          }

return true;

};

midhun_vp
Active Contributor
0 Kudos

The given code should work I think you are missing some code.

Lets debug the code. Try with only one validation.

function customBeforeMenuItemClick = function(screen, menuItem) {

         

    if (screen === "InventorySelection" && menuItem === "InventoryOverview")

{

              var form = document.forms[screen + "Form"];

              if (form)

        {

            var cost = form.Plant.value;

          

        }

               if (cost==null || cost == "")

{

                   alert("Please enter the mandatory fields");

                   return false;

         }

    }

    return true;

};

Check whether the above code is working. Hope you are using the write keys.

- Midhun VP

midhun_vp
Active Contributor
0 Kudos

Is this issue solved?

Answers (3)

Answers (3)

Former Member
0 Kudos

Thanks Midhun its working!!!

midhun_vp
Active Contributor
0 Kudos

Please close this thread marking the correct answer that help others to find the right answers quickly.

Former Member
0 Kudos

Nope!!!

Tried the same code its not working.

midhun_vp
Active Contributor
0 Kudos

The code given is a working one. Anyway lets debug it to find where it went wrong. Add alert ("step 1"); code inside the if loop

  if (screen === "InventorySelection" && menuItem === "InventoryOverview")

and

alert ("step 2"); inside   if (form)

and

alert ("step 3"); inside   if (cost==null || cost == "")

Check till which code it runs. You will get this alert in the device one by one when you run the app.

Double check the keys used.

- Midhun VP



midhun_vp
Active Contributor
0 Kudos

Is this issue solved?

midhun_vp
Active Contributor
0 Kudos

Please give complete information on the requirement so me or someone else can help you.

- Midhun VP