Reputation: 1476
I work with dynamics-crm 2016, my mission is - after the user click on new button (on form -to create a new record) the new form will load, I need to check a certain field and according to that field to lock my form.
When I check it from onLoad function the field is null, how can I check that my page has been loaded or all my fields are full in Xrm /Crm? My code:
function OnLoad() {
try {
if (formType == formTypes.Create) {
checkNeedsUnique();
}
} catch (e) {
frameworkGlobal.reportExceptionToServer(e);
}
};
//the function
function checkNeedsUnique(){
//portfolio return Null
var portfolio = Xrm.Page.getAttribute("protfolioid").getValue();
var filter = "needsSet?$select=needsId&$filter=protfolioid/Id eq guid'"+ portfolio[0].id+"' and statecode/Value eq 0";
var ret = frameworkGlobal.RetrieveMultiple(filter, false);
if(!!ret && ret.length>0){
disableAllFields();
}
}
Upvotes: 1
Views: 5100
Reputation: 755
Is this a typo in the attribute name?
Xrm.Page.getAttribute("protfolioid").getValue();
Shouldn't it be:
Xrm.Page.getAttribute("portfolioid").getValue();
Upvotes: 1
Reputation: 3586
If you are calling your function OnLoad
from onLoad event of your form, then all the fields have already been loaded. You cannot call it from some $(document).ready
because it will not work correctly.
The field that you are checking (the portfolio
) must exist on the form (or if you have Dynamics 365 9.0 you can add this field as your script dependencies). It can be hidden or it can be placed on some hidden section but it must be there, I believe that you did not put it on the form, or you put it on the header (where you should refer to it as "header_portfolioid"
), that's why you are getting null.
If by any means you cannot put it on the form, you will have to retrieve it's value using API call.
Upvotes: 1