cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MartinPAChamp
Helper I
Helper I

Add Regarding ID to E-mail Subject - Model Driven - E-Mail Table

Hi, 

 

I would like to be able to set the Regarding ID in to the Subject field as shown on the picture below, 

 

MartinPAChamp_0-1621952449749.png

I have tried the follow JS but having an error message, i am new to JS so any help would be great 🙂 

 

function GetCaseIDSetSubject() {
    //Get Uswer GUID and replace "{" and "}" with blanks. 
    var CaseID = formContext.getAttribute("regardingobjectid").getValue()[0].id;
    CaseID = CaseID.replace("{", "");
    CaseID = CaseID.replace("}", "");

    Xrm.WebApi.online.retrieveRecord("iii_enquiry", iii_enquiry, "?$select=iii_enquiry").then(
        function success(result) {
            var iii_enquiry = result["iii_enquiry"];
            var Subject = formContext.getAttribute("subject");
            //
            //Check if Subject contains data
            //
            if (Subject.getValue() != null) {
                var SubjectContainsID = Subject.getValue().includes(iii_enquiry);
                //
                //IF subject does not contain iii_enquiry, i add the iii_enquiry to the subject
                //
                if (SubjectContainsID == false) {
                    formContext.getAttribute("subject").setValue(Subject.getValue() + " - " + iii_enquiry);
                }
            } 
            //
            //This is a new email without a subject. Get the iii_enquiry, and inform that topic has to be set
            //
            else {
                formContext.getAttribute("subject").setValue("[Insert Topic] - " + iii_enquiry);
            }
        },
        function (error) {
            Xrm.Utility.alertDialog(error.message);
        }
    );

 

1 ACCEPTED SOLUTION

Accepted Solutions
MartinPAChamp
Helper I
Helper I

Got this working, here is the code , if any one is trying to do the same 🙂

 

function GetCaseIDSetSubject_2(executionContext) 

{
var formContext=executionContext.getFormContext();
    //Get Uswer GUID and replace "{" and "}" with blanks. 
    var iii_enquiry = formContext.getAttribute("regardingobjectid").getValue()[0].name;
    var Subject = formContext.getAttribute("subject")
         
   
//Check if Subject contains data
            //
            if (Subject.getValue() != null) {
                var SubjectContainsID = Subject.getValue().includes(iii_enquiry);
                //
                //IF subject does not contain Enquiry ID, i add the Enquiry ID to the subject
                //
                if (SubjectContainsID == false) {
                    formContext.getAttribute("subject").setValue(Subject.getValue() + " - " + iii_enquiry);
                }
            } 
            //
            //This is a new email without a subject. Get the Enquiry ID, and inform that topic has to be set
            //
            else {
                formContext.getAttribute("subject").setValue("[Insert Topic] - " + iii_enquiry);
            }
        }

View solution in original post

1 REPLY 1
MartinPAChamp
Helper I
Helper I

Got this working, here is the code , if any one is trying to do the same 🙂

 

function GetCaseIDSetSubject_2(executionContext) 

{
var formContext=executionContext.getFormContext();
    //Get Uswer GUID and replace "{" and "}" with blanks. 
    var iii_enquiry = formContext.getAttribute("regardingobjectid").getValue()[0].name;
    var Subject = formContext.getAttribute("subject")
         
   
//Check if Subject contains data
            //
            if (Subject.getValue() != null) {
                var SubjectContainsID = Subject.getValue().includes(iii_enquiry);
                //
                //IF subject does not contain Enquiry ID, i add the Enquiry ID to the subject
                //
                if (SubjectContainsID == false) {
                    formContext.getAttribute("subject").setValue(Subject.getValue() + " - " + iii_enquiry);
                }
            } 
            //
            //This is a new email without a subject. Get the Enquiry ID, and inform that topic has to be set
            //
            else {
                formContext.getAttribute("subject").setValue("[Insert Topic] - " + iii_enquiry);
            }
        }

View solution in original post

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Users online (1,248)