Java Script no Microsoft Dynamics CRM – Xrm.Page - Dynamics crm 365

Latest

Dicas do Dynamics crm 365

segunda-feira, 19 de junho de 2017

Java Script no Microsoft Dynamics CRM – Xrm.Page

Retornar URL do servidor

Xrm.Page.context.getClientUrl();
 Xrm.Utility.getGlobalContext().getClientUrl();

Retornar o GUID do usuário atual

 Xrm.Page.context.getUserId();
 Xrm.Utility.getGlobalContext().getUserId();

Retornar GUID do registro atual

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

Retornar GUID de um lookup

 Xrm.Page.data.entity.attributes.get("parentaccountid").getValue()[0].id;
 formContext.getAttribute("parentaccountid").getValue()[0].id;

Retornar texto de um lookup

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

Retornar o tipo de objeto de um lookup

 Xrm.Page.data.entity.attributes.get("parentaccountid").getValue()[0].entityType;
 formContext.getAttribute(("parentaccountid").getValue()[0].entityType;

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}]);
 formContext.getAttribute("parentaccountid").setValue( [{id: idValue, name: textValue, entityType: typeValue}]);

Desabilitar campo

 Xrm.Page.ui.controls.get("address1_addresstypecode").setDisabled(true);
 formContext.getControl("address1_addresstypecode").setDisabled(true);

Habilitar campo

 Xrm.Page.ui.controls.get("address1_addresstypecode").setDisabled(false);
 formContext.getControl("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;

Disparar o Evento OnChange em um campo

 Xrm.Page.getAttribute("FieldSchemaName").fireOnChange();

Ignorar dados do campo. Os dados não sera salvo

 Xrm.Page.getAttribute("name").setSubmitMode("never")

Verifica se o campo foi alterado

 Xrm.Page.getAttribute("name").getIsDirty()

Adicionar OnLoad no SubGrid

 var onloadSubGrid= function () { alert("Onlodd adicionado com sucesso") }; Xrm.Page.getControl("Contacts").addOnLoad(onloadSubGrid);

Mensagem de erro no campo

 Xrm.Page.getControl("campo").setNotification("Mensagem de erro mostrada no campo");

Limpar mensagem de erro no campo

 Xrm.Page.getControl('campo').clearNotification();

Validar se formulário é o HUB

 Xrm.Internal.isUci();

13 comentários:

  1. Excelente, me ajuda muito no dia a dia.

    ResponderExcluir
  2. Muito bom mesmo!

    O melhor site de tecnologia.

    ResponderExcluir
  3. Caraca, essa cor ficou muito top RafaMito. Tks a lot for this help.

    ResponderExcluir
  4. Não gostei, poderia ter um botão para copiar automaticamente a linha do código.

    ResponderExcluir
  5. Eu achei que tava bom, ai falaram que ia melhorar, mas não ficou muito bom, parece que ta piór, já tava ruim, agora parece que piorou.

    ResponderExcluir
  6. Xrm.Utility.getGlobalContext().userSettings.userId

    ResponderExcluir

Featured Post

Dicas rápidas de Power Automate

 Validar Listar Linhas contém dados empty(outputs('Listar_linhas' )?[ 'body/value' ]