terça-feira, 13 de março de 2012


Retornar URL do servidor

Xrm.Page.context.getServerUrl();

Retornar GUID do registro atual

Xrm.Page.data.entity.getId();

Retornar o GUID do usuário atual

Xrm.Page.context.getUserId();

Retornar GUID de um lookup

Xrm.Page.data.entity.attributes.get(“parentaccountid”).getValue()[0].id;

Retornar texto de um lookup

Xrm.Page.data.entity.attributes.get(“parentaccountid “).getValue()[0].name;

Retornar o tipo de objeto de um lookup

Xrm.Page.data.entity.attributes.get(“parentaccountid “).getValue()[0]. typename;

Retornar valor de campo

Xrm.Page.getAttribute(“name”).getValue();

Retornar valor de campo tipo picklist

Xrm.Page.getAttribute(“address1_addresstypecode”).getSelectedOption().value;

Retornar texto de campo tipo picklist

Xrm.Page.getAttribute(“address1_addresstypecode”).getSelectedOption().text;

Definir valor para um campo de texto

Xrm.Page.getAttribute(“address1_line1″).setValue(“Rua Primavera”);

Definir valor para campo do tipo pick list

Xrm.Page.getAttribute(“address1_addresstypecode “).setValue(2);

Definir valor para campo do tipo data

Xrm.Page.data.entity.attributes.get(“birthdate”).setValue(new Date());

Definir valor para campo do tipo dinheiro

Xrm.Page.getAttribute(“creditlimit”).setValue(parseFloat(eval(1200.35)));

Definir valor para campo do tipo decimal

Xrm.Page.getAttribute(“exchangerate”).setValue(parseFloat(eval(1.32)));

Definir valor para campo do tipo lookup

Xrm.Page.getAttribute(“parentaccountid”).setValue( [{id: idValue, name: textValue, entityType: typeValue}]);

Desabilitar campo

Xrm.Page.ui.controls.get(“address1_addresstypecode”).setDisabled(true);

Habilitar campo

Xrm.Page.ui.controls.get(“address1_addresstypecode”).setDisabled(false);

Esconder campo

Xrm.Page.ui.controls.get(“address1_addresstypecode “).setVisible(false);

Exibir campo

Xrm.Page.ui.controls.get(“address1_addresstypecode “).setVisible(true);

Esconder um item de navegação

Xrm.Page.ui.navigation.items.get(“navContacts”).setVisible(false);

Exibir um item de navegação

Xrm.Page.ui.navigation.items.get(“navContacts”).setVisible(true);

Esconder uma seção

Xrm.Page.ui.tabs.get(“tabName”).sections.get(“sectionName”).setVisible(false);

Exbir uma seção

Xrm.Page.ui.tabs.get(“tabName”).sections.get(“sectionName”).setVisible(true);

Salvar o formulário

Xrm.Page.data.entity.save();

Salvar e fechar o formuláirio

Xrm.Page.data.entity.save(“saveandclose”);

Fechar o formulário

Xrm.Page.ui.close();

Tipo do formulário

Xrm.Page.ui.getFormType(); //Create (1), Update (2), Read Only (3), Disabled (4), Bulk Edit (6)

Atualizar grid

Xrm.Page.ui.controls.get(“target_grid”). refresh();

Disparar evento de um campo

Xrm.Page.getAttribute(“parentaccountid”).fireOnChange();

Definir requerimento de campo

Xrm.Page.getAttribute(“parentaccountid”).setRequiredLevel(“none”);
Xrm.Page.getAttribute(“parentaccountid”).setRequiredLevel(“required”);
Xrm.Page.getAttribute(“parentaccountid”).setRequiredLevel(“recommended”);

Setar o foco no campo

Xrm.Page.getControl(“parentaccountid”).setFocus(true);

Interromper o evento de salvar

event.returnValue = false;

quinta-feira, 1 de março de 2012

FetchXML MSCRM 2011



//Obter dados do Programa
var TipoAtendimento = Xrm.Page.getAttribute("NOME_CAMPO_PARA_PESQUISA_1").getValue();
var TipoPublico = Xrm.Page.getAttribute(" NOME_CAMPO_PARA_PESQUISA_2").getValue();


//Construir o Fetchxml 
var viewId = "{65EC9B45-EE81-4F89-BAF6-E8603FF8E1E4}";
var entityName = "NOME_DA_ENTIDADE_RELACIONADA";
var viewDisplayName = "NOME_DA_EXIBICAO";


var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
"<entity name='NOME_DA_ENTIDADE_RELACIONADA'>" +
"<attribute name='NOME_CAMPO_RELACIONADO_1' />" +
"<attribute name='NOME_CAMPO_RELACIONADO_2' />" +
"<attribute name='NOME_CAMPO_RELACIONADO_3' />" +   
"<order attribute='NOME_CAMPO_PESQUISA' descending='false' />" +
"<order attribute='CHAVE_PRIMARIA' descending='false' />" +   
"<filter type='and'>" +
"<condition attribute='CAMPO_ENTIDADE_RELACIONA_PESQUISA_1' operator='eq' value='" + TipoPublico + "' />" + 
"<condition attribute='CAMPO_ENTIDADE_RELACIONA_PESQUISA_2' operator='eq' value='" + TipoAtendimento + "' />" +
"</filter>" +
"</entity>" +
"</fetch>";


//Construir o layout da grid de pesquisa (Exibição)
var layoutXml = "<grid name='resultset' " + "object='1' " + "jump='CHAVE_PRIMARIA' " + "select='1' " +  "icon='1' " + "preview='0'>" +
"<row name='result' " +  "id = 'CHAVE_PRIMARIA'>" +
"<cell name='NOME_CAMPO_RELACIONADO_1' " +  "width='250' />" +  
"<cell name='NOME_CAMPO_RELACIONADO_2' " +  "width='200' />" + 
"<cell name='NOME_CAMPO_RELACIONADO_3' " +  "width='200' />" +
"disableSorting='1' />" +
"</row>" +
"</grid>";


//Adicionar a nova visão
Xrm.Page.getControl("CAMPO_QUE_APARECERA_A_EXIBICAO").addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, true);