Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 82002

addPreScearch Portal

$
0
0

I have a form in the Portal, and I need to add a custom filter for a column. I have the script that works in Model Driven, but I can't adapt it to the Portal:

var Sdk = window.Sdk || {};

(function () {
	'use strict';
	this.GetTipoADR = function (executionContext) {
		//adiciona a funcao de filtro no campo lookup
		var formContext = executionContext.getFormContext();
		formContext.getControl("smt_tipodeevento").addPreSearch(controleTipos);
	};
}).call(Sdk);

function controleTipos(executionContext) {
	'use strict';
	var formContext = executionContext.getFormContext();
	var procedimento = formContext.getAttribute("smt_procedimento").getValue();
	//testa se o procedimento esta preenchido
	if (typeof (procedimento) !== "undefined" && procedimento !== null) {
		var id = formContext.getAttribute("smt_procedimento").getValue()[0].id;
		var type = formContext.getAttribute("smt_procedimento").getValue()[0].entityType;
		//busca os dados do tipo de procedimento, tipo de adr
		Xrm.WebApi.retrieveRecord(type, id, "?$select=smt_tipodeProcedimento&$expand=smt_tipodeProcedimento($select=smt_tipoadrid,smt_name)").then(
			function success(result) {
				var res = JSON.parse(JSON.stringify(result));
				//cria o filtro e o aplica
				var fetchXml = '<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true" count="50">' +
						'<entity name="smt_tipodeevento">' +
						'<attribute name="smt_nome" />' +
						'<attribute name="smt_tipodeeventoid" />' +
						'<attribute name="smt_podesercriadonoportal" />' +
						'<attribute name="smt_tipodeadr" />' +
						'<attribute name="createdon" />' +
						'<attribute name="statuscode" />' +
						'<attribute name="statecode" />' +
						'<filter type="and">' +
						'<condition attribute="smt_podesercriadonoportal" operator="eq" value="1" />' +
						'<condition attribute="smt_tipodeadr" operator="eq" value="' + result.smt_tipodeProcedimento.smt_tipoadrid + '" uiname="' + result.smt_tipodeProcedimento.smt_name + '" uitype="smt_tipoadr" />' +
						'</filter> </entity>';
				var layoutXml =	'<grid name="resultset" object="10352" jump="smt_nome" select="1" icon="1" preview="1" >' +
						'<row name="result" id="smt_tipodeeventoid" >' +
						'<cell name="smt_nome" width="200" />' +
						'<cell name="smt_tipodeadr" width="100" />' +
						'</row> </grid>'; 
				try {
					Xrm.Page.getControl("smt_tipodeevento").addCustomView('00000000-0000-0000-0000-000000000001', 'smt_tipodeevento', 'Portal', fetchXml, layoutXml, true);
				}
				catch (err) {
					var notificationTime = 10000;
					formContext.ui.setFormNotification(err.message, "WARNING", "Warning");
					setTimeout(
						function () {
							formContext.ui.clearFormNotification("Warning");
						},
						notificationTime
					);
				}
			},
			function (error) {
				var notificationTime = 10000;
				formContext.ui.setFormNotification(error.message, "WARNING", "Warning");
				setTimeout(
					function () {
						formContext.ui.clearFormNotification("Warning");
					},
					notificationTime
				);
				// handle error conditions
			});
	}
}

Viewing all articles
Browse latest Browse all 82002

Latest Images

Trending Articles



Latest Images