var ODataContract;(function(b){var a=function(){function a(a){this.TemplateId=a}a.prototype.getMetadata=function(){var a={boundParameter:null,parameterTypes:{TemplateId:{typeName:"Edm.String",structuralProperty:1}},operationName:"msdyn_GetKAObjectFromTemplate",operationType:0};return a};return a}();b.msdyn_GetKAObjectFromTemplate=a})(ODataContract||(ODataContract={}));var KnowledgeManagement;(function(b){var a=function(){function a(){}a.ChooseLanguageDialogUniqueName="KMChooseLanguage";a.KATemplateLogicalName="msdyn_knowledgearticletemplate";a.LanguageLookupId="translateLanguageLocale_id";a.lastButtonClicked="param_lastButtonClicked";a.languageDetails="param_selectedLanguage";a.languageNameControl="header_msdyn_LanguageLocaleIdName";a.languageIdControl="msdyn_languagelocaleid";a.subjectId="msdyn_subjectid";a.OK_ID="ok_id";a.CANCEL_ID="cancel_id";a.templateDetails="param_msdyn_knowledgearticletemplateId";a.tempDescCheck="---";a.SelectKnowledgeArticleTemplateUniqueName="SelectKnowledgeArticleTemplate";a.languageResponse="_languagelocaleid_value";a.subjectResponse="_subjectid_value";a.selectTemplateLookupId="selectTemplate_id";a.KnowledgeArticleLogicalName="knowledgearticle";return a}();b.Constants=a;var c=function(){function a(){}a.TelemetryEvent_EventOnLoad="OnLoad";a.TelemetryEvent_CreateArticleFromTemplate="CreateArticleFromTemplate";a.TelemetryEvent_LinkLookupForArticle="LinkLookupForArticle";a.TelemetryEvent_OpenLanguageDialog="OpenLanguageDialog";return a}();b.TelemetryConstants=c;var d=function(){function d(){var e=this;this.onLoad=function(){Xrm.Page.ui.getFormType()==1&&e.openLanguageDialog();Xrm.Page.getControl(a.languageNameControl).setDisabled(true)};this.openLanguageDialog=function(){var b={height:300,width:500,position:1};Xrm.Navigation.openDialog(a.ChooseLanguageDialogUniqueName,b).then(function(b){if(b&&b.parameters&&b.parameters[a.lastButtonClicked]==a.OK_ID)e.handleFormChanges(b.parameters);else Xrm.Page.ui.close()},function(a){d.actionFailedCallbackForMoca(a,c.TelemetryEvent_OpenLanguageDialog)})};this.handleFormChanges=function(f){var d=f[a.languageDetails];if(d){var e=JSON.parse(d),c=Xrm.Page.getControl(a.languageIdControl)&&Xrm.Page.getControl(a.languageIdControl).getAttribute(),b=Xrm.Page.getControl(a.languageNameControl)&&Xrm.Page.getControl(a.languageNameControl).getAttribute();if(c&&b){c.setValue(e.id.replace(/[{}]/g,""));b.setValue(e.name);Xrm.Page.getControl(a.languageNameControl).setDisabled(true)}}};this.onDialogSaveHelper=function(){var e=Xrm.Page.getControl(a.LanguageLookupId),c=e.getAttribute()&&e.getAttribute().getValue(),d=null;if(c&&c.length>0)d=JSON.stringify(c[0]);else{var f={text:b.ResourceStringProvider.getResourceString("KnowledgeArticle_SelectLanguage_SelectLanguageMessage")},g={width:600,height:150,position:1};Xrm.Navigation.openAlertDialog(f,g);return}Xrm.Page.data.attributes.get(a.languageDetails).setValue(d);Xrm.Page.ui.close()};this.onDialogSave=function(){var b=Xrm.Page.data.attributes.get(a.lastButtonClicked);b&&b.setValue(a.OK_ID);e.onDialogSaveHelper()};this.onDialogCancel=function(){var b=Xrm.Page.data.attributes.get(a.lastButtonClicked);b&&b.setValue(a.CANCEL_ID);Xrm.Page.ui.close()};this.onDialogTemplateCancel=function(){var c=Xrm.Page.data.entity&&Xrm.Page.data.entity.attributes.get("description"),b=Xrm.Page.data.attributes.get(a.lastButtonClicked);if(b){b.setValue(a.CANCEL_ID);c&&c.setValue("")}Xrm.Page.ui.close()};this.openSelectKATemplateDialog=function(){var b={entityName:"knowledgearticle",entityId:null},c={description:a.tempDescCheck};Xrm.Navigation.openForm(b,c)};this.knowledgeArticle_onload=function(){var b=null,f=false;if(Xrm.Page.data.entity&&Xrm.Page.data.entity.attributes.get("description")){b=Xrm.Page.data.entity.attributes.get("description").getValue();if(b)f=b===a.tempDescCheck}if(Xrm.Page.ui.getFormType()==1&&b!=null&&f){var g={height:300,width:500,position:1};Xrm.Navigation.openDialog(a.SelectKnowledgeArticleTemplateUniqueName,g).then(function(b){var c=Xrm.Page.data.entity&&Xrm.Page.data.entity.attributes.get("description");c&&c.setValue("");b&&b.parameters&&b.parameters[a.lastButtonClicked]==a.OK_ID&&e.createArticleFromTemplate(b.parameters)},function(a){d.actionFailedCallbackForMoca(a,c.TelemetryEvent_EventOnLoad)})}};this.createArticleFromTemplate=function(g){var f=g[a.templateDetails];if(f){var h=new ODataContract.msdyn_GetKAObjectFromTemplate(f),b=[];b.push(Xrm.WebApi.online.execute(h).then(function(a){return a.json()}));b.push(Xrm.Utility.getEntityMetadata(a.KnowledgeArticleLogicalName));Promise.all(b).then(function(g){var a=null,f;if(g[0])a=g[0];if(g[1])f=g[1];if(f!=null&&a!=undefined&&a!=null){var c=f._entityDescriptor.AttributeNames;if(c!=null){for(var b in c)if(a[c[b]]!=undefined&&a[c[b]]!=null){var k=c[b].toString(),i=Xrm.Page.data.entity&&Xrm.Page.data.entity.attributes.get(k);i&&i.setValue(a[c[b]])}var d=f._entityDescriptor.ManyToOneRelationships;if(d&&a)for(var b in d)if(d[b].ReferencingAttribute){var l=d[b].ReferencedEntity,h=d[b].ReferencingAttribute,j="_"+h+"_value";a[j]&&e.linkLookupForArticle(l,a[j],h)}}}},function(a){d.actionFailedCallbackForMoca(a&&a.innerror||a,c.TelemetryEvent_CreateArticleFromTemplate)})}};this.linkLookupForArticle=function(a,e,b){a&&Xrm.Utility.getEntityMetadata(a).then(function(c){var d="?$filter="+c.PrimaryIdAttribute+" eq "+e+"";Xrm.WebApi.retrieveMultipleRecords(a,d).then(function(e){var d;if(e&&e.entities.length>0)d=e.entities[0];if(d&&c){var i=c.PrimaryNameAttribute,j=d[i],k=d[c.PrimaryIdAttribute],f=Xrm.Page.getAttribute(b);if(f!=null){var g={entityType:a,id:k,name:j},h=[g];f.setValue(h)}}},function(){})},function(a){d.actionFailedCallbackForMoca(a,c.TelemetryEvent_LinkLookupForArticle)})};this.selectTemplateFromDialog=function(){var b=Xrm.Page.data.attributes.get(a.lastButtonClicked);b&&b.setValue(a.OK_ID);e.createArticleTemplateOkClick()};this.createArticleTemplateOkClick=function(){var f=Xrm.Page.getControl(a.selectTemplateLookupId),c=f.getAttribute(),d=null;if(c){var e=c.getValue();if(e)d=e[0].id;else{var g={text:b.ResourceStringProvider.getResourceString("KnowledgeArticle_SelectTemplate_SelectTemplateMessage")},h={width:600,height:150,position:1};Xrm.Navigation.openAlertDialog(g,h);return}}Xrm.Page.data.attributes.get(a.templateDetails).setValue(d);Xrm.Page.ui.close()}}d.getFormContext=function(a){if(a==null||a==undefined)return Xrm.Page;else return a.getFormContext()};d.reportFailureEvent=function(a,c,e,b,d){var a=a+"."+c;Xrm.Reporting.reportFailure(a,e,b,d)};d.actionFailedCallbackForMoca=function(b,a){Xrm.Utility.closeProgressIndicator();d.actionFailedCallback(a,b)};d.actionFailedCallback=function(c,b){if(b){d.reportFailureEvent(a.KnowledgeArticleLogicalName,c,{name:c,message:b.hasOwnProperty("message")?b.message:b.toString()});var e={errorCode:b.errorCode,message:b.message};Xrm.Navigation.openErrorDialog(e)}};return d}();b.KnowledgeCommandBarActions=d;var e=function(){function a(){}a.Instance=new d;return a}();b.CommandBarActions=e})(KnowledgeManagement||(KnowledgeManagement={}))
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,113 Super User 2024 Season 2
Martin Dráb 229,918 Most Valuable Professional
nmaenpaa 101,156