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 :
Microsoft Dynamics CRM (Archived)

Create URL from a number of fields using javascript

(0) ShareShare
ReportReport
Posted on by 32

Hi!

I am trying to create a URL field based on a number of fields within any given company page. The main problem i am encountering is when trying to add the primary contact of a company to the string. It resolves to object Object instead of the name of the contact. Is thier anyway to pull the name of the contact that is recorded within a company? Below is my current JS

function CreateURL() {

var employeeEmail = Xrm.Page.data.entity.attributes.get("mc_nutraceuticalsowner").getValue();
var distributor = Xrm.Page.data.entity.attributes.get("mc_distributorforms").getValue();
var pharmacyName = Xrm.Page.data.entity.attributes.get("name").getValue();
var pharmacyAccountNumber = Xrm.Page.data.entity.attributes.get("mc_membershipnumber").getValue();
var state = Xrm.Page.data.entity.attributes.get("mc_stateforms").getValue();
var customerContactName = Xrm.Page.data.entity.attributes.get("primarycontactid").getValue();

var accountUrl = "https://forms.example.com/view.php?element_279="+employeeEmail+"&element_5="+distributor+"&element_34="+pharmacyName+"&element_33="+pharmacyAccountNumber+"&element_51="+state+"&element_280="+customerContactName+"&id=20314";

Xrm.Page.data.entity.attributes.get("mc_accounturl").setValue(accountUrl);

}

The current URL being given from the script is: 

https://forms.example.com/view.php?element_279=%5bobject%20Object%5d&element_280=%5bobject%20Object%5d&element_33=1111111&element_34=Medlab%20Clinical%20LTD&element_5=3&element_51=1

*This post is locked for comments

I have the same question (0)
  • HarryZang Profile Picture
    240 on at

    The "primarycontactid" is a lookup field, it is actually a lookup array,

    so you need to get the value by using the following code

    var customerContactName = Xrm.Page.data.entity.attributes.get("primarycontactid")[0].getValue();  //try access the property of the object, you should able to get the fullname

    Please note, add null check when necessary, otherwise the code may broke,

    In addition, you may need to encode your URL as well.

  • Suggested answer
    Guido Preite Profile Picture
    54,086 Moderator on at

    change this line

    var customerContactName = Xrm.Page.data.entity.attributes.get("primarycontactid").getValue();

    to

    var customerContactName = "";

    var customerValue = Xrm.Page.data.entity.attributes.get("primarycontactid").getValue();

    if (customerValue != null) { customerContactName = customerValue[0].name; }

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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans