Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

how to set the Name of activity as “Customer Name – Purpose – Status” Using JavaScript

Posted on by Microsoft Employee

I have an invitation activity and I want when I save it to appear instead of the name as the "customer name-purpose-status"

I used this code but its not working ..

function setname()
{
var customername=Xrm.Page.getAttribute("new_customer").getValue();
var purpose=Xrm.Page.getAttribute("new_purpose").getValue();
var status=Xrm.Page.getAttribute("new_status").getValue();
var activityname=Xrm.Page.getAttribute("new_customer","new_purpose","new_status").getValue();

Xrm.Page.getAttribute("activityname").setValue("Customer Name – Purpose – Status");
}

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: how to set the Name of activity as “Customer Name – Purpose – Status” Using JavaScript

    Refer this:

    arunpotti.wordpress.com/.../get-lookup-id-text-entityname-in-crm-using-javascript

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: how to set the Name of activity as “Customer Name – Purpose – Status” Using JavaScript

    function setname()

    {

    var lookup = new Array();

    lookup = Xrm.Page.getAttribute("new_customer").getValue();

    var purpose=Xrm.Page.getAttribute("new_purpose").getValue();

    var status=Xrm.Page.getAttribute("new_status").getSelectedOption().value;

    Xrm.Page.getAttribute("subject").setValue(lookup + "-" + purpose + "-" + status);

    }

    I correct it this way .. no more error but its giving me the name of the activity:

    [object Object]-testing 33-100000000

    any suggestion ??

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: how to set the Name of activity as “Customer Name – Purpose – Status” Using JavaScript

    Saad Thank you, but I needed to know the syntax of the lookuo field since customer name is a lookup, status is an option set, however Rahul have right function with error in the syntax in the customer name like the following code:

    function setname()

    {

    // in the customer name I need to know the syntax of the lookup field

    var customername=Xrm.Page.getAttribute("new_customer").getValue();

    var purpose=Xrm.Page.getAttribute("new_purpose").getValue();

    var status=Xrm.Page.getAttribute("new_status").getOptionSet();

    Xrm.Page.getAttribute("subject").setValue(customername + "-" + purpose + "-" + status);

    }

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: how to set the Name of activity as “Customer Name – Purpose – Status” Using JavaScript
    function setname()
    {
    var activityname = Xrm.Page.getAttribute("activityname").getValue();
    if(activityname)
    return;
    var name = "";
    var customername=Xrm.Page.getAttribute("new_customer").getValue();
    var purpose=Xrm.Page.getAttribute("new_purpose").getValue();
    var status=Xrm.Page.getAttribute("new_status");
    if (customername)
    { name = name + customername[0].name;
    }
    if (purpose)
    { name = name + " - " + purpose;
    }
    if (status.getValue())
    { name = name + " - " + status.getText();
    }
    Xrm.Page.getAttribute("activityname").setValue(name);
    }
  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: how to set the Name of activity as “Customer Name – Purpose – Status” Using JavaScript

    ahh I notice something .. customer name is a lookup field, and status is a an option set, do you know the syntax of the lookup field?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: how to set the Name of activity as “Customer Name – Purpose – Status” Using JavaScript

    function setname()

    {

    var activityname = Xrm.Page.getAttribute("activityname").getValue();

    if(activityname)

    return;

    var name = "";

    var customername=Xrm.Page.getAttribute("new_customer").getValue();

    var purpose=Xrm.Page.getAttribute("new_purpose").getValue();

    var status=Xrm.Page.getAttribute("new_status");

    if (customername)

    { name = name + customername;

    }

    if (purpose)

    { name = name + " - " + purpose;

    }

    if (status.getValue())

    { name = name + " - " + status.getText();

    }

    Xrm.Page.getAttribute("activityname").setValue(name);

    }

  • Rahul G J Profile Picture
    Rahul G J 605 on at
    RE: how to set the Name of activity as “Customer Name – Purpose – Status” Using JavaScript

    Hi Sorry there was typo error, plz try this

    function setname()

    {

    var customername=Xrm.Page.getAttribute("new_customer").getValue();

    var purpose=Xrm.Page.getAttribute("new_purpose").getValue();

    var status=Xrm.Page.getAttribute("new_status").getValue();

    Xrm.Page.getAttribute("activityname").setValue(customername + "-" + purpose + "-" + status");

    }

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: how to set the Name of activity as “Customer Name – Purpose – Status” Using JavaScript

    Hey,

    Thanks Rahul & Saad yes both codes are giving me error

  • Rahul G J Profile Picture
    Rahul G J 605 on at
    RE: how to set the Name of activity as “Customer Name – Purpose – Status” Using JavaScript

    Hi,

    Plz try this

    function setname()

    {

    var customername=Xrm.Page.getAttribute("new_customer").getValue();

    var purpose=Xrm.Page.getAttribute("new_purpose").getValue();

    var status=Xrm.Page.getAttribute("new_status").getValue();

    Xrm.Page.getAttribute("activityname").setValue(Customer Name + "-" + Purpose + "-" + Status");

    }

    Is this giving any error ?

    Regards,

    Rahul

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: how to set the Name of activity as “Customer Name – Purpose – Status” Using JavaScript

    I tried your code it gave me this error :

    Microsoft Dynamics CRM Error Report Contents

    <CrmScriptErrorReport>

     <ReportVersion>1.0</ReportVersion>

     <ScriptErrorDetails>

      <Message>Uncaught SyntaxError: missing ) after argument list</Message>

      <Line>6</Line>

      <URL>/%7B636235328080000359%7D/WebResources/new_name?ver=-444613272</URL>

      <PageURL>/form/page.aspx?lcid=1033&themeId=f499443d-2082-4938-8842-e7ee62de9a23&tstamp=562775&updateTimeStamp=636215421355511937&userts=131324096371955952&ver=-444613272#etc=10020&extraqs=%3fetc%3d10020&pagemode=iframe&pagetype=entityrecord&counter=1487936087177</PageURL>

      <Function>anonymousror:missing)afterargumentlist</Function>

      <FunctionRaw>SyntaxError: missing ) after argument list</FunctionRaw>

      <CallStack>

       <Function>anonymousror:missing)afterargumentlist</Function>

      </CallStack>

     </ScriptErrorDetails>

     <ClientInformation>

      <BrowserUserAgent>Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36</BrowserUserAgent>

      <BrowserLanguage>undefined</BrowserLanguage>

      <SystemLanguage>undefined</SystemLanguage>

      <UserLanguage>undefined</UserLanguage>

      <ScreenResolution>1600x900</ScreenResolution>

      <ClientName>Web</ClientName>

      <ClienState>Online</ClienState>

      <ClientTime>2017-02-24T13:34:47</ClientTime>

     </ClientInformation>

     <ServerInformation>

       <OrgLanguage>1033</OrgLanguage>

       <OrgCulture>1033</OrgCulture>

       <UserLanguage>1033</UserLanguage>

       <UserCulture>1033</UserCulture>

       <OrgID>{8843AA2D-56E8-E611-80D7-00155D004F8B}</OrgID>

       <UserID>{A6EBB65E-56E8-E611-80D7-00155D004F8B}</UserID>

       <CRMVersion>8.1.0.359</CRMVersion>

     </ServerInformation>

    </CrmScriptErrorReport>

    <CrmScriptErrorReport>

     <ReportVersion>1.0</ReportVersion>

     <ScriptErrorDetails>

      <Message>Uncaught SyntaxError: missing ) after argument list</Message>

      <Line>6</Line>

      <URL>/%7B636235328080000359%7D/WebResources/new_name?ver=-444613272</URL>

      <PageURL>/form/page.aspx?lcid=1033&themeId=f499443d-2082-4938-8842-e7ee62de9a23&tstamp=562775&updateTimeStamp=636215421355511937&userts=131324096371955952&ver=-444613272#etc=10020&extraqs=%3fetc%3d10020&pagemode=iframe&pagetype=entityrecord&counter=1487936087177</PageURL>

      <Function>anonymousror:missing)afterargumentlist</Function>

      <FunctionRaw>SyntaxError: missing ) after argument list</FunctionRaw>

      <CallStack>

       <Function>anonymousror:missing)afterargumentlist</Function>

      </CallStack>

     </ScriptErrorDetails>

     <ClientInformation>

      <BrowserUserAgent>Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36</BrowserUserAgent>

      <BrowserLanguage>undefined</BrowserLanguage>

      <SystemLanguage>undefined</SystemLanguage>

      <UserLanguage>undefined</UserLanguage>

      <ScreenResolution>1600x900</ScreenResolution>

      <ClientName>Web</ClientName>

      <ClienState>Online</ClienState>

      <ClientTime>2017-02-24T13:34:47</ClientTime>

     </ClientInformation>

     <ServerInformation>

       <OrgLanguage>1033</OrgLanguage>

       <OrgCulture>1033</OrgCulture>

       <UserLanguage>1033</UserLanguage>

       <UserCulture>1033</UserCulture>

       <OrgID>{8843AA2D-56E8-E611-80D7-00155D004F8B}</OrgID>

       <UserID>{A6EBB65E-56E8-E611-80D7-00155D004F8B}</UserID>

       <CRMVersion>8.1.0.359</CRMVersion>

     </ServerInformation>

    </CrmScriptErrorReport>

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans