Skip to main content

Notifications

Dynamics 365 general forum
Answered

Work Order Force Quick Form on Subgrids

Posted on by 35

On the work order quotes how do we get it to load "New Work Order Product" via the Quick Create Form. It seems all the system sub grids on the work order want to open stuff in the "Modal Dialog" I believe what's referred to. Problem is we have a custom Save & New Function. The save and new function and Xrm.Navigate I don't think support Modal dialog, so we programmed it to open a quick form instead. Everything works fine but looks odd to start 1 item as a modal dialog then 2nd item as a Quick Form. We like to just have it all Modal or all Quick Form. I guess this solution can kind of go one or two ways. Need help in getting the subgrid to just default to Quick Form, or help adjusting the code, so it opens a Modal Dialog instead. So, any help is appreciated. 

const wait = (ms = 0) => new Promise(resolve => { setInterval(resolve, ms) });

async function SaveAndNew_WOProduct() {
    Xrm.Page.data.save();
    await wait(2000);
    var getLookupData = Xrm.Page.data.entity.attributes.get("msdyn_workorder").getValue();
    var workOrderID = getLookupData[0].id;
    var workOrderName = getLookupData[0].name;
    await wait(2000);
    OpenNewForm_WOProduct(workOrderID, workOrderName);
    Xrm.Page.ui.close();
}


function OpenNewForm_WOProduct(id, name) {
    //https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/xrm-navigation/openform

    var entityFormOptions = {};
    entityFormOptions["entityName"] = "msdyn_workorderproduct";
    entityFormOptions["useQuickCreateForm"] = true;
    
    // Set default values for the form
    var formParameters = {};
    
    // Set lookup column
    formParameters["msdyn_workorder"] = id;
    formParameters["msdyn_workordername"] = name;
    formParameters["msdyn_workordertype"] = "msdyn_workorder";
    // End of set lookup column
    
    // Open the form.
    Xrm.Navigation.openForm(entityFormOptions, formParameters).then(
        function (success) {
            console.log(success);
        },
        function (error) {
            console.log(`Error: ${error}`);
    });

}

  • jdaniel1 Profile Picture
    jdaniel1 35 on at
    RE: Work Order Force Quick Form on Subgrids

    Ah so close! K i modified this around a bit and got it working.

    In case anybody wants my final code bit (Fairly the same as yours, but includes Data Input Example):

    function OpenNewForm_WOProduct(id, name) {
        //https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/xrm-navigation/navigateto
    
        var pageInput = {
            pageType: "entityrecord",
            entityName: "msdyn_workorderproduct",
            data: {
                //Map Lookup Fields
                "msdyn_workorder": id,
                "msdyn_workordername": name,
                "msdyn_workordertype": "msdyn_workorder"
            }
        };
        var navigationOptions = {
            target: 2,
            height: { value: 80, unit: "%" },
            width: { value: 70, unit: "%" },
            position: 1
        };
        Xrm.Navigation.navigateTo(pageInput, navigationOptions).then(
            function success(result) {
                console.log("Record created with ID: "   result.savedEntityReference[0].id  
                    " Name: "   result.savedEntityReference[0].name)
                // Handle dialog closed
            },
            function error() {
                // Handle errors
            }
        );
    
    }

  • Suggested answer
    RE: Work Order Force Quick Form on Subgrids

    Hello jdaniel1,

    Please have a look to this, it should resolve the point : learn.microsoft.com/.../navigateto

    There is an example to open an existing record

    var pageInput = {
        pageType: "entityrecord",
        entityName: "account",
        entityId: "5a57f2c3-5672-ea11-a812-000d3a339706" //replace with actual ID
    };
    var navigationOptions = {
        target: 2,
        height: {value: 80, unit:"%"},
        width: {value: 70, unit:"%"},
        position: 1
    };
    Xrm.Navigation.navigateTo(pageInput, navigationOptions).then(
        function success() {
                // Run code on success
        },
        function error() {
                // Handle errors
        }
    );

    Regards,

    Amira

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,524 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,493 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans