web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Preselect pdf layout based on field in the quote context

(3) ShareShare
ReportReport
Posted on by 7
For a customer of ours we need to preselect the used template for exporting a quote, based on a field in the quote context.
I don't find anything on the internet. Is there anyone who has experience with this?
 
I have the standard code here, where it passes some parameters but don't seem to see anything there...
 
 
var AppCommon;
(function (AppCommon) {
    var CommandActions = (function () {
        function CommandActions() { }

        /*
         * The below function launches the PDF dialog with a preselected template
         */
        CommandActions.LaunchPDFDialog = function () {
            var dialogOptions = {
                width: 1090,
                height: 625,
                position: 1 /* center */
            };

            var dialogParams = {};
            var entityReference = Xrm.Page.data.entity.getEntityReference();
            dialogParams["param_entityId"] = entityReference.id;
            dialogParams["param_entityType"] = entityReference.entityType;
            dialogParams["param_entityTypeCode"] = Xrm.Internal.getEntityCode(entityReference.entityType);
            dialogParams["param_templateType"] = 2; // Word document enum code
            dialogParams["param_documentType"] = "pdf";

            Xrm.Navigation.openDialog("ShowPDFPreview", dialogOptions, dialogParams);
        };

        return CommandActions;
    }());

    AppCommon.CommandActions = CommandActions;

    // Ribbon Rules for enabling/disabling the PDF button
    var RibbonRules = (function () {
        function RibbonRules() { }

        RibbonRules.isPdfCommandEnabled = function (entity) { 
            return __awaiter(this, void 0, void 0, function () {
                var isPdfSettingEnabled, data, settingObject, settingValue, err_1;
                return __generator(this, function (_a) {
                    switch (_a.label) {
                        case 0:
                            _a.trys.push([0, 3, , 4]);
                            isPdfSettingEnabled = sessionStorage.getItem(entity + "_isPdfSettingEnabled");
                            if (isPdfSettingEnabled) {
 
I have the same question (0)
  • Suggested answer
    Holly Huffman Profile Picture
    6,530 Super User 2025 Season 2 on at
    Good morning, afternoon, or evening depending on your location!
    I see this was posted quite a while ago - hoping you've already resolved but incase not, here are some thoughts:
     
    You can achieve this by incorporating logic to retrieve the desired layout based on the field value and then pass this information in the dialog parameters.
    Here's an adjusted example:
     
    var AppCommon;
    (function (AppCommon) {
        var CommandActions = (function () {
            function CommandActions() { }

    /*
             * The below function launches the PDF dialog with a preselected template
             */
            CommandActions.LaunchPDFDialog = function () {
                var dialogOptions = {
                    width: 1090,
                    height: 625,
                    position: 1 /* center */
                };

    var dialogParams = {};
                var entityReference = Xrm.Page.data.entity.getEntityReference();
                dialogParams["param_entityId"] = entityReference.id;
                dialogParams["param_entityType"] = entityReference.entityType;
                dialogParams["param_entityTypeCode"] = Xrm.Internal.getEntityCode(entityReference.entityType);
                dialogParams["param_documentType"] = "pdf";

    // Retrieve the field value from the quote context
                var fieldValue = Xrm.Page.getAttribute("yourFieldName").getValue();

    // Logic to determine the template type based on the field value
                if (fieldValue === "Template1") {
                    dialogParams["param_templateType"] = 1; // Template1 enum code
                } else if (fieldValue === "Template2") {
                    dialogParams["param_templateType"] = 2; // Template2 enum code
                } else {
                    dialogParams["param_templateType"] = 0; // Default template enum code
                }

    Xrm.Navigation.openDialog("ShowPDFPreview", dialogOptions, dialogParams);
            };

    return CommandActions;
        }());

    AppCommon.CommandActions = CommandActions;
    })();

    Key Adjustments:
    1. Field Value Retrieval: Replace "yourFieldName" with the actual schema name of the field in the quote entity that determines the layout.
    2. Template Selection Logic: Adjust the conditions and template codes (1, 2, etc.) to correspond to your business requirements.
    Ribbon Rule Adjustments:
    To ensure the PDF button is enabled only when this field has a valid value, update the RibbonRules.isPdfCommandEnabled function with logic to check the field value:
    RibbonRules.isPdfCommandEnabled = function (entity) {
        return __awaiter(this, void 0, void 0, function () {
            var fieldValue, isPdfSettingEnabled;
            return __generator(this, function (_a) {
                isPdfSettingEnabled = sessionStorage.getItem(entity + "_isPdfSettingEnabled");
                fieldValue = Xrm.Page.getAttribute("yourFieldName").getValue();
               
                // Enable PDF button only if fieldValue is not null/undefined
                return [2 /*return*/, isPdfSettingEnabled && fieldValue];
            });
        });
    };

     
    Hope this helps some!

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 170 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 61

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 52 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans