Forum Discussion

john john's avatar
john john
Steel Contributor
Mar 04, 2019

how i can add a "PreSaveItem()" function inside the modern UI

I have a custom list inside our sharepoint on-premises 2013, where i added the following "PreSaveItem()" script inside the Edit/Create list forms:-

 

function PreSaveItem(){
//codes goes here
if( status == "Closed")
{

if( ana.trim() == null
|| ana.trim().length <= 1){
errormessage = number+") Please Enter 'Analysis' field before closing the item \n";
result = false;
number++;
}
if(category == "Complaint" && (conclusion.trim() == null || conclusion.trim().length <= 1)){
errormessage = errormessage+number+") Please Enter 'Conclusion' field before closing the item \n";
result = false;
number++;
}
}
if(errormessage.length >= 1)
{
alert(errormessage);

}
return result;
}

 

now i am planning to migrate the list to sharepoint online, and per my test the above script will work if i render the online list inside classic UI, while if i render the online list inside the modern UI, the script will not have any effect, so my question is about the approaches i can follow to have a function which mimic the "PreSaveItem()" function inside our modern online UI?

Thanks

  • You cannot inject JavaScript and/or modify out of the box forms in Modern UI with client side code. If you need to customize forms, you will need to use PowerApps, or stay in the classic UI.

    • john john's avatar
      john john
      Steel Contributor

      Beau Cameron wrote:

      You cannot inject JavaScript and/or modify out of the box forms in Modern UI with client side code. If you need to customize forms, you will need to use PowerApps, or stay in the classic UI.


      Beau Cameronthanks for your reply.

      Yes i know that inside modern UI i can not edit the Edit/Create list forms... But if i chose power-apps then can i inset a script which will run before the form is submitted? similar to how the "PreSaveItem()" works?

      • Beau Cameron's avatar
        Beau Cameron
        MVP

        In PowerApps, there is no "injecting" a script. However, you can do this type of validation within PowerApps, using the PowerApps Language (similar to DAX).

Resources