Looking for PowerObjects? Don’t worry, you’re in the right place! We’ve been part of HCL for several years, and we’ve now taken the final step in our acquisition journey: moving our website to the HCL domain. Nothing else is changing – we are still fanatically focused on Microsoft Business Applications!

PowerObjects Blog 

for Microsoft Business Applications

| |

Using Form Save with Custom Web Resources

Post Author: Joe D365 |

Microsoft has provided plenty of tools for use when out-of-the-box customizations fall short. Using custom web resources on forms can be a powerful tool, but it should integrate seamlessly with the form. To accomplish this, the web resource can hook onto the save of the form. This provides an easy way for users to interact across the different parts of the form without having to worry about multiple toolbars. In today's blog, we'll show you how it's done!

Let's say we have a web resource that surfaces information from a different entity, or a different source all together, and allows user input. In just a few simple steps, we can save any data we need from the web resource at the same time as the form.

1. Retrieve initial modifiedon information:

var modifiedon = parent.Xrm.Page.getAttribute("modifiedon").getValue();

2. Set up callbacks:

parent.Xrm.Page.data.entity.addOnSave(function(context){

    //Trigger any necessary calls here

});

parent.Xrm.Page.getAttribute("modifiedon").addOnChange(function(context){

    modifiedOn = context.getFormContext().getAttribute("modifiedon").getValue();

});

3. Set modifiedon based on user interaction in the web resource:

If(WebResource Needs To Save){

    Xrm.Page.getAttribute("modifiedon").setValue(new Date());

}

else{

    Xrm.Page.getAttribute("modifiedon").setValue(modifiedOn);

}

While the user interacts with the web resource, it is setting the modifiedon field to either the saved date or a new date. This will make the form appear dirty whenever the web resource requires a save, or other function call, to happen. Users will no longer know they are interacting with a separate web resource.

We hope this comes in handy for you. For more tips and tricks – be sure to check out our blog!

Happy D365'ing!

Joe CRM
By Joe D365
Joe D365 is a Microsoft Dynamics 365 superhero who runs on pure Dynamics adrenaline. As the face of PowerObjects, Joe D365’s mission is to reveal innovative ways to use Dynamics 365 and bring the application to more businesses and organizations around the world.

PowerObjects Recommends