Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Error on customization page

(0) ShareShare
ReportReport
Posted on by 1,777

Hi,

I am getting error on page when I add below code and publish.  Kindly help me to find the error.  How to find the error. But the script is working and I am getting Presales team name. 

Please find the script and screen.  I added this script to get option set text which marked in bold letters.

will this scripts make any issue when upgrade CRM 2011 to CRM 2013 to CRM 2015

function productid_onchange()
{


if (Xrm.Page.getAttribute("productid").getValue() != null )
{
var itemid = Xrm.Page.getAttribute("productid").getValue()[0].id;
var context = Xrm.Page.context;
serverUrl = context.getServerUrl(); 
var ODataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc";
var retrieveResult = new XMLHttpRequest();
retrieveResult.open("GET", ODataPath + "/ProductSet?$select=ProductTypeCode,New_PresalesTeam&$filter=ProductId eq guid'" + itemid + "'", false);

retrieveResult.setRequestHeader("Accept", "application/json");
retrieveResult.setRequestHeader("Content-Type", "application/json; charset=utf-8");
retrieveResult.send();
alert(retrieveResult.readyState);
alert(retrieveResult.status);
if (retrieveResult.readyState == 4 )
   {
     alert("2");
      if (retrieveResult.status == 200)
            {
            alert("3");
            var retrieved = JSON.parse(retrieveResult.responseText).d;

Xrm.Page.getAttribute("new_categorytype").setValue(retrieved.results[0].ProductTypeCode.Text);

Xrm.Page.getAttribute("new_presalesteam").setValue(retrieved.results[0].New_PresalesTeam.Text);

             var ptype =retrieved.results[0].ProductTypeCode.Value;
             var pteam = retrieved.results[0].New_PresalesTeam.Value;
     }
    }


}


SDK.Metadata.RetrieveAttribute("product", "new_presalesteam", null, true, function (result) {

for (var i = 0; i < result.OptionSet.Options.length; i++) {
   if (result.OptionSet.Options[i].Value == pteam)
{ var text = result.OptionSet.Options[i].Label.LocalizedLabels[0].Label;
alert(text);
 var value = result.OptionSet.Options[i].Value;
alert(value);
}
 }
 },
 function (error) {
 alert("error");
 }
 );

if (Xrm.Page.getAttribute("uomid").getValue() == null)
  {
    
 var lookupData = new Array();

 var lookupItem= new Object();

   lookupItem.id = '{40AE01DD-385B-43E0-8698-00D1E9462CCF}';

   lookupItem.typename = 'Unit';

   lookupItem.name = 'EACH';

   lookupData[0] = lookupItem;
   Xrm.Page.getAttribute("uomid").setValue(lookupData);
   Xrm.Page.getAttribute("uomid").setSubmitMode("always");

    }

}

3858.error-2.png

error-on-page.png

*This post is locked for comments

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

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

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,436 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans