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,...
Answered

Cannot read property 'indexOf' of null in addCustomView UCI

(0) ShareShare
ReportReport
Posted on by

Hi experts!

i am getting this error "Cannot read property 'indexOf' of null" while using addCustomView in Dynamic 365 CRM UCI and register this event on change of this field "poc_vehicles"

Code:

function defaultToPurchasedVehicles(executionContext) {

var attribute = "poc_vehicles";
var formContext = executionContext.getFormContext();
var viewId = "{DDE2FB22-52C7-EA11-A812-000D3AB5D04F}";
var entityName = "sl_vehicle";
var viewDisplayName = "Purchased vehicles";
var isDefault = true;

var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"
fetchXml += "<entity name='sl_vehicle'>"
fetchXml += "<attribute name='sl_name' />"
fetchXml += "<attribute name='sl_yearnumber' />"
fetchXml += "<attribute name='sl_registrationnumber' />"
fetchXml += "<attribute name='sl_model' />"
fetchXml += "<attribute name='sl_make' />"
fetchXml += "<attribute name='sl_vehicleid' />"
fetchXml += "<order attribute='sl_name' descending='false' />"
fetchXml += "<filter type='and'>"
fetchXml += "<condition attribute='statuscode' operator='eq' value='1' />"
fetchXml += "</filter>"
fetchXml += "<link-entity name='contact' from='contactid' to='sl_vehiclesid' link-type='inner' alias='ab'>"
fetchXml += "<filter type='and'>"
fetchXml += "<condition attribute='sl_vehiclepurchasestatus' operator='in'>"
fetchXml += "<value>{8C17A6FF-07A4-E911-A837-000D3AB18F6D}</value>"
fetchXml += "<value>{8D17A6FF-07A4-E911-A837-000D3AB18F6D}</value>"
fetchXml += "<value>{8E17A6FF-07A4-E911-A837-000D3AB18F6D}</value>"
fetchXml += "</condition>"
fetchXml += "</filter>"
fetchXml += "</link-entity>"
fetchXml += "</entity>"
fetchXml += "</fetch>";

var layoutXml = "<grid name='resultset' object='4230' jump='name' select='1' icon='1' preview='1'>" +
"<row name='result' id='userqueryid'>" +
"<cell name='name' width='300 />" +
"<cell name='ownerid' width='100' />" +
"<cell name='modifiedon' width='100' />" +
"</row>" +
"</grid>";

formContext.getControl(attribute).addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, isDefault);
}


Regards,
ZG

I have the same question (0)
  • Wahaj Rashid Profile Picture
    11,321 on at

    Hi,

    Did you make sure Execution Context is being passed?

    Also, the attribute (poc_vehicles) is available on the form?

    Best,

    Wahaj

  • ZeeshanGhause Profile Picture
    on at

    Thanks but i have added these checks


    if ((attribute != "" && viewId != "" && entityName != "" && viewDisplayName != "" && fetchXml != "" && layoutXml != "" && isDefault != false) && (attribute != null && viewId != null && entityName != null && viewDisplayName != null && fetchXml != null && layoutXml != null && isDefault != false)) {
    formContext.getControl(attribute).addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, isDefault);
    }

    still getting same error
    see

    pastedimage1594905103192v1.png

  • Verified answer
    Wahaj Rashid Profile Picture
    11,321 on at

    Hi,

    Can you check following line in layoutXML:

    "<row name='result' id='userqueryid'>"

    I guess id should be name of the id field of 'sl_vehicle' entity for example 'sl_vehicl_id', can you try?

    Best,

    Wahaj

  • ZeeshanGhause Profile Picture
    on at

    i just created layout xml of view from xrmtool and then it works

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
Pallavi Phade Profile Picture

Pallavi Phade 96

#2
Tom_Gioielli Profile Picture

Tom_Gioielli 69 Super User 2025 Season 2

#3
Gerardo Rentería García Profile Picture

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

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans