Answered by:
disable Add New button on subgrid

Question
-
Hi,
I want to disable Add New Record from subgrid. I created custom Javascript Enable rule for the Add New Button and I used the function below.
Everythig that I get as a result is correct (true if the status is ok, false if its not) but the button is still enabled no matter what status the record is in. What am I doing wrong?
function GetEntity(entityID, entityName,entityColumns, handleData) { var url = Xrm.Page.context.getServerUrl()+"/xrmservices/2011/OrganizationData.svc/" + entityName+ "Set" + "(guid'" + entityID+ "')"; if(entityColumns != null && entityColumns.length >0) url = url +"?$select="+entityColumns; $.ajax({ type: "GET", contentType: "application/json; charset=utf-8", datatype: "json", url: url, beforeSend: function (xhr) { //Specifying this header ensures that the results will be returned as JSON. xhr.setRequestHeader("Accept", "application/json"); }, success: function (data, textStatus, xhr) { //JQuery does not provide an opportunity to specify a date reviver so this code // parses the xhr.responseText rather than use the data parameter passed by JQuery. handleData(JSON.parse(xhr.responseText, function (key, value) { var a; if (typeof value === 'string') { a = /Date\(([-+]?\d+)\)/.exec(value); if (a) { return new Date(parseInt(value.replace("/Date(", "").replace(")/", ""), 10)); } } return value;}).d); }, error: function (xhr, textStatus, errorThrown) { alert("Error occured"); } }); } function checkStatus(recordId, entityName) { alert(entityName); alert("RecordId" + recordId); if (recordId == "") {return;} if (entityName == "") {return;} if (recordId.length == 0) {return;} var data = GetEntity(recordId[0], entityName, 'statuscode', function(data) { if(data != null) { if(data.statuscode!= null) { if(data.statuscode.Value == 100000002) { alert("true"); return true; } else { alert("false"); return false; } } } }); }
- Edited by mimamar Thursday, August 22, 2013 9:48 AM
Thursday, August 22, 2013 9:36 AM
Answers
-
Hi,
Your requirement could be easily met by using Value Rule.
Example
<EnableRule Id="mcg.activitypointer.EnableRule0.EnableRule">
<ValueRule Field="statuscode" Value="true" Default="false" InvertResult="true" />
</EnableRule>
Kindly Vote as helpful or mark as answer if it has helped
Regards,
Darrel
Happy Coding
- Proposed as answer by Payman BiukaghazadehEditor Monday, September 2, 2013 12:52 PM
- Marked as answer by Payman BiukaghazadehEditor Tuesday, September 17, 2013 4:44 AM
Monday, September 2, 2013 10:08 AM -
Hi,
If you want to permanently remove the add new button from the ribbon, you may reach it without any customization. Just make the lookup field on the 1:N relationship as not required, then there would be no add new button on the child entity.
- Proposed as answer by Payman BiukaghazadehEditor Monday, September 2, 2013 12:53 PM
- Marked as answer by Payman BiukaghazadehEditor Tuesday, September 17, 2013 4:44 AM
Monday, September 2, 2013 12:52 PMModerator
All replies
-
Hi,
Your requirement could be easily met by using Value Rule.
Example
<EnableRule Id="mcg.activitypointer.EnableRule0.EnableRule">
<ValueRule Field="statuscode" Value="true" Default="false" InvertResult="true" />
</EnableRule>
Kindly Vote as helpful or mark as answer if it has helped
Regards,
Darrel
Happy Coding
- Proposed as answer by Payman BiukaghazadehEditor Monday, September 2, 2013 12:52 PM
- Marked as answer by Payman BiukaghazadehEditor Tuesday, September 17, 2013 4:44 AM
Monday, September 2, 2013 10:08 AM -
Hi,
If you want to permanently remove the add new button from the ribbon, you may reach it without any customization. Just make the lookup field on the 1:N relationship as not required, then there would be no add new button on the child entity.
- Proposed as answer by Payman BiukaghazadehEditor Monday, September 2, 2013 12:53 PM
- Marked as answer by Payman BiukaghazadehEditor Tuesday, September 17, 2013 4:44 AM
Monday, September 2, 2013 12:52 PMModerator