Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

approve custom button is not working 2016

Posted on by Microsoft Employee

Hi Friends,

We recently upgraded CRM 2011 to CRM 2016,we have  Approve custom button in Home and subgrid level its not working in CRM 2016 on premise.

Displaying image001.png

Ribbon Diff xml file:

 

<RibbonDiffXml>

  <CustomActions>

    <CustomAction Id="phm.HomepageGrid.ics_timecardline.MainTab.Collaborate.Approve.Button.CustomAction" Location="Mscrm.HomepageGrid.ics_timecardline.MainTab.Collaborate.Controls._children" Sequence="51">

      <CommandUIDefinition>

        <Button Command="HomepageGrid.ics_timecardline.Approve.Command" Id="HomepageGrid.ics_timecardline.MainTab.Collaborate.Approve.Button" Image32by32="$webresource:ics_TimeEntryApprove32" Image16by16="$webresource:ics_TimeEntryApprove16" LabelText="$LocLabels:HomepageGrid.ics_timecardline.MainTab.Collaborate.Approve.Button.LabelText" Sequence="51" TemplateAlias="o1" ToolTipTitle="$LocLabels:HomepageGrid.ics_timecardline.MainTab.Collaborate.Approve.Button.ToolTipTitle" ToolTipDescription="$LocLabels:HomepageGrid.ics_timecardline.MainTab.Collaborate.Approve.Button.ToolTipDescription" />

      </CommandUIDefinition>

    </CustomAction>

    <CustomAction Id="phm.HomepageGrid.ics_timecardline.MainTab.Collaborate.Reject.Button.CustomAction" Location="Mscrm.HomepageGrid.ics_timecardline.MainTab.Collaborate.Controls._children" Sequence="53">

      <CommandUIDefinition>

        <Button Command="HomepageGrid.ics_timecardline.Reject.Command" Id="HomepageGrid.ics_timecardline.MainTab.Collaborate.Reject.Button" Image32by32="$webresource:ics_TimeEntryDisapprove32" Image16by16="$webresource:ics_TimeEntryDisapprove16" LabelText="$LocLabels:HomepageGrid.ics_timecardline.MainTab.Collaborate.Reject.Button.LabelText" Sequence="53" TemplateAlias="o1" ToolTipTitle="$LocLabels:HomepageGrid.ics_timecardline.MainTab.Collaborate.Reject.Button.ToolTipTitle" ToolTipDescription="$LocLabels:HomepageGrid.ics_timecardline.MainTab.Collaborate.Reject.Button.ToolTipDescription" />

      </CommandUIDefinition>

    </CustomAction>

    <CustomAction Id="phm.SubGrid.ics_timecardline.MainTab.Collaborate.Approve.Button.CustomAction" Location="Mscrm.SubGrid.ics_timecardline.MainTab.Collaborate.Controls._children" Sequence="53">

      <CommandUIDefinition>

        <Button Command="HomepageGrid.ics_timecardline.Approve.Command" Id="SubGrid.ics_timecardline.MainTab.Collaborate.Approve.Button" Image32by32="$webresource:ics_TimeEntryApprove32" Image16by16="$webresource:ics_TimeEntryApprove16" LabelText="$LocLabels:SubGrid.ics_timecardline.MainTab.Collaborate.Approve.Button.LabelText" Sequence="53" TemplateAlias="o3" ToolTipTitle="$LocLabels:SubGrid.ics_timecardline.MainTab.Collaborate.Approve.Button.ToolTipTitle" ToolTipDescription="$LocLabels:SubGrid.ics_timecardline.MainTab.Collaborate.Approve.Button.ToolTipDescription" />

      </CommandUIDefinition>

    </CustomAction>

    <CustomAction Id="phm.SubGrid.ics_timecardline.MainTab.Collaborate.Reject.Button.CustomAction" Location="Mscrm.SubGrid.ics_timecardline.MainTab.Collaborate.Controls._children" Sequence="56">

      <CommandUIDefinition>

        <Button Command="HomepageGrid.ics_timecardline.Reject.Command" Id="SubGrid.ics_timecardline.MainTab.Collaborate.Reject.Button" Image32by32="$webresource:ics_TimeEntryDisapprove32" Image16by16="$webresource:ics_TimeEntryDisapprove16" LabelText="$LocLabels:SubGrid.ics_timecardline.MainTab.Collaborate.Reject.Button.LabelText" Sequence="56" TemplateAlias="o3" ToolTipTitle="$LocLabels:SubGrid.ics_timecardline.MainTab.Collaborate.Reject.Button.ToolTipTitle" ToolTipDescription="$LocLabels:SubGrid.ics_timecardline.MainTab.Collaborate.Reject.Button.ToolTipDescription" />

      </CommandUIDefinition>

    </CustomAction>

  </CustomActions>

  <Templates>

    <RibbonTemplates Id="Mscrm.Templates"></RibbonTemplates>

  </Templates>

  <CommandDefinitions>

    <CommandDefinition Id="HomepageGrid.ics_timecardline.Approve.Command">

      <EnableRules>

        <EnableRule Id="AtLeastOneSelected.EnableRule" />

      </EnableRules>

      <DisplayRules />

      <Actions>

        <JavaScriptFunction FunctionName="TimeEntry.Approve" Library="$webresource:ics_TimeEntryJS.js">

          <CrmParameter Value="SelectedControlSelectedItemIds" />

          <CrmParameter Value="SelectedControl" />

        </JavaScriptFunction>

      </Actions>

    </CommandDefinition>

    <CommandDefinition Id="HomepageGrid.ics_timecardline.Reject.Command">

      <EnableRules>

        <EnableRule Id="AtLeastOneSelected.EnableRule" />

      </EnableRules>

      <DisplayRules />

      <Actions>

        <JavaScriptFunction FunctionName="TimeEntry.Reject" Library="$webresource:ics_TimeEntryJS.js">

          <CrmParameter Value="SelectedControlSelectedItemIds" />

          <CrmParameter Value="SelectedControl" />

        </JavaScriptFunction>

      </Actions>

    </CommandDefinition>

  </CommandDefinitions>

  <RuleDefinitions>

    <TabDisplayRules />

    <DisplayRules />

    <EnableRules>

      <EnableRule Id="AtLeastOneSelected.EnableRule">

        <SelectionCountRule AppliesTo="SelectedEntity" Minimum="1" />

      </EnableRule>

    </EnableRules>

  </RuleDefinitions>

  <LocLabels>

    <LocLabel Id="HomepageGrid.ics_timecardline.MainTab.Collaborate.Approve.Button.LabelText">

      <Titles>

        <Title description="Approve" languagecode="1033" />

      </Titles>

    </LocLabel>

    <LocLabel Id="HomepageGrid.ics_timecardline.MainTab.Collaborate.Approve.Button.ToolTipDescription">

      <Titles>

        <Title description="Approve the selected Timecard Lines" languagecode="1033" />

      </Titles>

    </LocLabel>

    <LocLabel Id="HomepageGrid.ics_timecardline.MainTab.Collaborate.Approve.Button.ToolTipTitle">

      <Titles>

        <Title description="Approve" languagecode="1033" />

      </Titles>

    </LocLabel>

    <LocLabel Id="HomepageGrid.ics_timecardline.MainTab.Collaborate.Reject.Button.LabelText">

      <Titles>

        <Title description="Reject" languagecode="1033" />

      </Titles>

    </LocLabel>

    <LocLabel Id="HomepageGrid.ics_timecardline.MainTab.Collaborate.Reject.Button.ToolTipDescription">

      <Titles>

        <Title description="Reject the selected Timecard Lines" languagecode="1033" />

      </Titles>

    </LocLabel>

    <LocLabel Id="HomepageGrid.ics_timecardline.MainTab.Collaborate.Reject.Button.ToolTipTitle">

      <Titles>

        <Title description="Reject" languagecode="1033" />

      </Titles>

    </LocLabel>

    <LocLabel Id="SubGrid.ics_timecardline.MainTab.Collaborate.Approve.Button.LabelText">

      <Titles>

        <Title description="Approve" languagecode="1033" />

      </Titles>

    </LocLabel>

    <LocLabel Id="SubGrid.ics_timecardline.MainTab.Collaborate.Approve.Button.ToolTipDescription">

      <Titles>

        <Title description="Approve the selected Timecard Lines" languagecode="1033" />

      </Titles>

    </LocLabel>

    <LocLabel Id="SubGrid.ics_timecardline.MainTab.Collaborate.Approve.Button.ToolTipTitle">

      <Titles>

        <Title description="Approve" languagecode="1033" />

      </Titles>

    </LocLabel>

    <LocLabel Id="SubGrid.ics_timecardline.MainTab.Collaborate.Reject.Button.LabelText">

      <Titles>

        <Title description="Reject" languagecode="1033" />

      </Titles>

    </LocLabel>

    <LocLabel Id="SubGrid.ics_timecardline.MainTab.Collaborate.Reject.Button.ToolTipDescription">

      <Titles>

        <Title description="Reject the selected Timecard Lines" languagecode="1033" />

      </Titles>

    </LocLabel>

    <LocLabel Id="SubGrid.ics_timecardline.MainTab.Collaborate.Reject.Button.ToolTipTitle">

      <Titles>

        <Title description="Reject" languagecode="1033" />

      </Titles>

    </LocLabel>

  </LocLabels>

</RibbonDiffXml>

Javascript:

TimeEntry.Approve = function (ids, homepageGrid, onSuccess) {
var validRecords = ids;
if (typeof homepageGrid != "undefined" && homepageGrid != null) {
var validRecords = TimeEntry.RetrieveApprovableOrRejectableCount(ids);
if (validRecords.length == 0) {
alert("You can't approve any of the selected Timecard Lines.\nPossible reasons:\nThe Timecard Line is not submitted.\nYou are not the Manager of the Timecard Line.");
return
}
if (ids.length != validRecords.length) {
if (!confirm("You can approve just " + validRecords.length + " of the selected Timecard Lines.\nPossible reasons:\nThe Timecard Line is not submitted.\nYou are not the Manager of the Timecard Line.\nDo you want to approve those " + validRecords.length + " Timecard Lines?")) {
return;
}
}
if (typeof SDK == "undefined" || typeof SDK.JQuery == "undefined") {
TimeEntry.LoadJS("/WebResources/newSDK.JQuery.js");
}
}
recordsToUpdate = validRecords.length;
recordsUpdated = 0;
recordsAction = "Timecard Lines Approved"
for (var i = 0; i < validRecords.length; i++) {
TimeEntry.ChangeState(validRecords[i], "newtimecardline", 1, 2, function () {
TimeEntry.SuccessMessage(homepageGrid, onSuccess);
}, homepageGrid);
}
}

TimeEntry.ChangeState = function (id, logicalName, state, status, onSuccess, homepageGrid) {
// create the request
var request = "<s:Envelope xmlns:s=\"schemas.xmlsoap.org/.../envelope\">";
request += "<s:Body>";
request += "<Execute xmlns=\"schemas.microsoft.com/.../Services\" xmlns:i=\"www.w3.org/.../XMLSchema-instance\">";
request += "<request i:type=\"b:SetStateRequest\" xmlns:a=\"schemas.microsoft.com/.../Contracts\" xmlns:b=\"schemas.microsoft.com/.../Contracts\">";
request += "<a:Parameters xmlns:c=\"schemas.datacontract.org/.../System.Collections.Generic\">";
request += "<a:KeyValuePairOfstringanyType>";
request += "<c:key>EntityMoniker</c:key>";
request += "<c:value i:type=\"a:EntityReference\">";
request += "<a:Id>" + id + "</a:Id>";
request += "<a:LogicalName>" + logicalName + "</a:LogicalName>";
request += "<a:Name i:nil=\"true\" />";
request += "</c:value>";
request += "</a:KeyValuePairOfstringanyType>";
request += "<a:KeyValuePairOfstringanyType>";
request += "<c:key>State</c:key>";
request += "<c:value i:type=\"a:OptionSetValue\">";
request += "<a:Value>" + state + "</a:Value>";
request += "</c:value>";
request += "</a:KeyValuePairOfstringanyType>";
request += "<a:KeyValuePairOfstringanyType>";
request += "<c:key>Status</c:key>";
request += "<c:value i:type=\"a:OptionSetValue\">";
request += "<a:Value>" + status + "</a:Value>";
request += "</c:value>";
request += "</a:KeyValuePairOfstringanyType>";
request += "</a:Parameters>";
request += "<a:RequestId i:nil=\"true\" />";
request += "<a:RequestName>SetState</a:RequestName>";
request += "</request>";
request += "</Execute>";
request += "</s:Body>";
request += "</s:Envelope>";
//send set state request
$.ajax({
type: "POST",
async: false,
contentType: "text/xml; charset=utf-8",
datatype: "xml",
url: Xrm.Page.context.getClientUrl() + "/XRMServices/2011/Organization.svc/web",
data: request,
beforeSend: function (XMLHttpRequest) {
XMLHttpRequest.setRequestHeader("Accept", "application/xml, text/xml, */*");
XMLHttpRequest.setRequestHeader("SOAPAction", "schemas.microsoft.com/.../Execute");
},
success: function (data, textStatus, XmlHttpRequest) {
onSuccess();
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
var details = XMLHttpRequest.responseXML.documentElement.getElementsByTagName("faultstring");
var errorText = errorThrown;
if (details != null && details.length > 0) {
if (typeof details[0].text != "undefined") {
errorText = details[0].text;
} else if (typeof details[0].textContent != "undefined") {
errorText = details[0].textContent;
}
}
TimeEntry.ErrorMessage(homepageGrid, errorText);
}
});
}
TimeEntry.RetrieveApprovableOrRejectableCount = function (ids) {
if (typeof $ == "undefined") {
TimeEntry.LoadJS("/WebResources/newjquery");
}
if (typeof CrmFetchKit == "undefined") {
var httpRequest = new XMLHttpRequest();
httpRequest.open("GET", Xrm.Page.context.getClientUrl() + "/WebResources/newCrmFetchKit", false);
httpRequest.send();
try {
eval(httpRequest.responseXML);
} catch (e) {
alert("Error loading " + resource + ":\n" + e.description);
}
}
var idFilters = "<condition attribute='newtimecardlineid' operator='in'>";
for (var i = 0; i < ids.length; i++) {
idFilters += "<value>" + ids[i] + "</value>";
}
idFilters += "</condition>";
var fetchxml = "<?xml version='1.0' encoding='UTF-8'?><fetch distinct='false' mapping='logical' output-format='xml-platform' version='1.0'><entity name='newtimecardline'><attribute name='newtimecardlineid' /><filter type='and'><condition attribute='statuscode' value='802430000' operator='eq' />" + idFilters + "</filter><link-entity name='newtimecard' from='newtimecardid' to='newtimecardid' link-type='inner'><filter type='and'><condition attribute='newapproverid' operator='eq' value='" + Xrm.Page.context.getUserId() + "'/></filter></link-entity></entity></fetch>";
var approvableOrRejectable = [];
var results = CrmFetchKit.FetchSync(fetchxml);
for (var i in results) {
approvableOrRejectable.push(results[i].Id);
}
return approvableOrRejectable;
}

the above code working in 2011 when its upgraded to 2016 its not working.

thanks for help.

 

Mohammad, Habeeb

Add to circles

Show details

 

*This post is locked for comments

  • Suggested answer
    PS Profile Picture
    PS 23,577 on at
    RE: approve custom button is not working 2016

    Code Upgrade might be required:

    msdn.microsoft.com/.../gg509046(v=crm.6).aspx

    msdn.microsoft.com/.../gg334220(v=crm.6).aspx

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