DataVerse JavaScript Useful Things

JavaScript to save a form:

function saveRecordOnChange(executionContext) {

    try {
        let formContext = executionContext.getFormContext();
        if (formContext) {
            let confirmStrings = { text: "This is the text in the dialog box", title: "This is the Title" };
            let confirmOptions = { height: 200, width: 450 };

            // Open Confirm Dialog
            Xrm.Navigation.openConfirmDialog(confirmStrings, confirmOptions).then(
                function (success) {
                    if (success.confirmed) {
                        // Save the Record if OK is clicked
    catch (ex) {
        throw new Error(ex.message);

Get and Set Values:

// get a field value
// set a field value

Set entities to search on a look up: See MS Docs

function onFormRestrictEntity(executionContext) {
        var formContext = executionContext.getFormContext();



Get User Info including GUID

For full user context see the MS doc.

// Get the User GUID
var UserId = Xrm.Utility.getGlobalContext().userSettings.userId.replace("{", "").replace("}", "");

Use the built in dialogs

Xrm.Navigation.openErrorDialog({ message: 'The important Date field needs to be populated.'});

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s