您的位置:首页 > 汽车 > 时评 > 电商运营是干嘛的_产品发布网站_站长基地_廊坊seo排名公司

电商运营是干嘛的_产品发布网站_站长基地_廊坊seo排名公司

2024/12/21 20:07:50 来源:https://blog.csdn.net/lisenustc/article/details/144475993  浏览:    关键词:电商运营是干嘛的_产品发布网站_站长基地_廊坊seo排名公司
电商运营是干嘛的_产品发布网站_站长基地_廊坊seo排名公司

Dynamics 365 CRM 后端插件语法示例

public IPluginExecutionContext context = null;//上下文
public IOrganizationServiceFactory serviceFactory = null;//组织服务工厂对象
public IOrganizationService service = null;//Org服务对象//创建执行上下文
context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
//创建组织服务工厂对象
serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
//Org服务对象
service = serviceFactory.CreateOrganizationService(context.UserId);
//触发当前插件的那条记录
Entity entity= service.Retrieve(context.PrimaryEntityName, context.PrimaryEntityId, new ColumnSet(true));

查询

QueryExpression query = new QueryExpression("EntityName");
query.ColumnSet = new ColumnSet("EntityNameid");
query.Criteria = new FilterExpression(LogicalOperator.And);//条件与
query.Criteria.AddCondition("id", ConditionOperator.Equal, corpid);
query.Criteria.AddCondition("id", ConditionOperator.Equal, userid);
var list = svcContext.RetrieveMultiple(query).Entities.ToList();

添加:

Entity entity = new Entity("EntityName");
entity.Attributes.Add("date", DateTime.Now);
conn.CallerId = new Guid(list[0].Attributes["EntityNameid"].ToString());
OrganizationServiceProxy orgServiceNew = conn.OrganizationServiceProxy;
orgServiceNew.Create(entity);

修改

 Entity invoiceEntity = conn.Retrieve("EntityName", new Guid(id), new ColumnSet(true));svcContext.Attach(invoiceEntity);invoiceEntity.Attributes["修改的字段"] = longitude;svcContext.UpdateObject(invoiceEntity);svcContext.SaveChanges();

批量事务处理:

ExecuteTransactionRequest req = new ExecuteTransactionRequest();
OrganizationRequestCollection org = new OrganizationRequestCollection();
//添加
CreateRequest snInformationCreate = new CreateRequest();
snInformationCreate.Target = snInformation;
org.Add(snInformationCreate);
//修改
UpdateRequest entupdate = new UpdateRequest();
entupdate.Target = item;
org.Add(entupdate);
//执行事务
req.Requests = org;
orgService.Execute(req);

CRM字段类型:

类型名称:    值类型
单行/多行文本:    String
查找:    new EntityReference(objecttypename,Guid)
选项集    new OptionSet(Int)
两个选项:    false/true
整数:    Integer
浮点数:    Double
十进制数:    Decimal
货币:    new Money(Decimal)
日期和时间:    DateTime
存储列表值:    StringMap
存储附件:    annotation

窗体状态

获取窗体状态类型
var formType = Xrm.Page.ui.getFormType();
表单类型
0尚未定义
1创建
2更新
3只读
4已禁用
6批量编辑

//获取当前用户id
Xrm.Page.context.getUserId(); 
//获取当前用户的用户名    
Xrm.Page.context.getUserName();
//获取当用户的安全角色         
Xrm.Page.context.getUserRoles();
//获取当前用户   
Xrm.Page.context.getUser();  
//获取字段名为“name”的字段值        
Xrm.Page.getAttribute("name").getValue(); 
//给字段名为“name”的字段赋值    
Xrm.Page.getAttribute("name").setValue("Inputer");
//给字段名为“name”的字段赋值后自动提交        
Xrm.Page.getAttribute("name").setSubmitMode("Inputer"); 
//页面保存并刷新
Xrm.Page.data.save().then(function () {parent.window.location.reload();});     
//保存  
Xrm.Page.data.entity.save();
//刷新
Xrm.Page.data.refresh();  
//取流程的值
var phase = Xrm.Page.data.process.getActiveStage().getName(); 
//改变字段的字段需求  (注:required业务必选;none可选;recommended业务推荐)
Xrm.Page.getAttribute("字段名").setRequiredLevel("required");   
//隐藏名为“st_portfoliomanager”的字段            
Xrm.Page.getControl("st_portfoliomanager").setVisible(false); 
//取消隐藏(显示)名为“st_portfoliomanager”的字段       
Xrm.Page.getControl("st_portfoliomanager").setVisible(true); 
//锁字段名为“ownerid”的字段(注:页眉的字段加header_)       
Xrm.Page.getControl("ownerid").setDisabled(true);
//解锁字段名为“ownerid”的字段         
Xrm.Page.getControl("ownerid").setDisabled(false); 
//局部刷新(子网格也可以局部刷新)       
Xrm.Page.getControl("st_customerneed").refresh(); 
//删除选项集中的选项         
Xrm.Page.getControl("字段名").removeOption("值");  
//获取父页面的值
window.top.opener.Xrm.Page.getAttribute('tec_phase').getValue();
//隐藏tab
Xrm.Page.ui.tabs.get("tab_20").setVisible(false);
//获取当前页面的状态(注:1为新建,2为修改)    
Xrm.Page.ui.getFormType();
//关闭当前页面        
Xrm.Page.ui.close(); 
//打开页面    
Xrm.Utility.openEntityForm("实体名称", getEntityId);  
//获取当前记录id  
Xrm.Page.data.entity.getId();     
//获取当前记录name 
Xrm.Page.data.entity.getEntityName()
//设置tab标题
Xrm.Page.ui.tabs.getByName("tab_15").setLabel("文档" + "(" + docDatas.length + ")");  
//change事件
Xrm.Page.data.process.addOnStageChange(fnStageChanged);  
//select事件
Xrm.Page.data.process.addOnStageSelected(fnStageSelected); 
//获取当前Stage
var currentStage = execContext.getEventArgs().getStage(); 
//获取当前窗体名称
Xrm.Page.ui.formSelector.getCurrentItem().getLabel() 
//给字段绑定事件
Xrm.Page.getControl("header_new_salescontract_id").getAttribute().addOnChange(function () {}
//按节锁字段Xrm.Page.ui.controls.forEach(function (control) {if (control.getParent()!=null) {if (control.getParent().getName() != null) {name = control.getAttribute().getName()if (control.getParent().getName() == "tab_1_sections") {control.setDisabled(true);}}}})
//刷新父页面
window.top.opener.Xrm.Utility.openEntityForm(window.top.opener.Xrm.Page.data.entity.getEntityName(), window.top.opener.Xrm.Page.data.entity.getId());
//字段错误信息
Xrm.Page.getControl("attributeName").setNotification("notification content");
Xrm.Page.getControl("attributeName").clearNotification();
//窗体错误信息
Xrm.Page.ui.setFormNotification("notification content", "type", "notification name");//type:"INFORMATION","ERROR","WARNING"
Xrm.Page.ui.clearFormNotification('notification name');//clear all form notification when parameter is null```
//加载层
Xrm.Utility.showProgressIndicator("Please Wait.");
//禁用字段方法
function IsTrueDisabled(sectionlable, trueorfalse) {var tabs = Xrm.Page.ui.tabs;for (var i = 0, teblenth = tabs.getLength(); i < teblenth; i++) {var tab = tabs.get(i);var sections = tab.sections;for (var j = 0, sectionslenth = sections.getLength(); j < sectionslenth; j++) {var section = sections.get(j);if (section._controlName) {if (section._controlName.toLowerCase() == sectionlable) {Xrm.Page.ui.controls.forEach(function (control) {if (control.getParent() !== null && control._controlName != "tec_teammemberid" && control.getParent()._controlName === sectionlable && control.getControlType() !== "subgrid") {control.setDisabled(trueorfalse);}});break;}}}}
}
//获取页面层级
function getXrmObj () {var XRMOBJ = new Object();if (typeof Xrm != "undefined") {XRMOBJ = Xrm}else if (typeof window.parent.Xrm != "undefined") {XRMOBJ = window.parent.Xrm}else if (typeof window.opener.Xrm != "undefined") {XRMOBJ = window.opener.Xrm}else if (typeof window.opener.parent.Xrm != "undefined") {XRMOBJ = window.opener.parent.Xrm}else {throw new Error("Context is not available.");}return XRMOBJ;}
//隐藏选项卡
formContext.ui.tabs.get("tab_3").setVisible(false);
//隐藏节
formContext.ui.tabs.get("{ad0f2413-1961-40cd-8563-09e9b8e48aea}").sections.get("tab_3_section_1").setVisible(false);
//刷新导航栏按钮
formContext.ui.refreshRibbon(true);

Xrm.Page.data(客户端引用) | Microsoft Learn

一、常用语句-用户

Xrm.Page.context.getUserId();       //获取当前用户id
Xrm.Page.context.getUserName();       //获取当前用户的用户名
//获取当用户的安全角色(这个不建议用作权限判断使用,测试发现不同的用户,同一个角色查到的角色ID不同)
Xrm.Page.context.getUserRoles();  //获取用户角色id
Xrm.Utility.getGlobalContext().userSettings.roles;//获取用户角色ID及名称信息     
Xrm.Page.context.getUser();        //获取当前用户

二、常用语句-实体

实体属性获取

Xrm.Page.data.entity.getId(); //获取当前 Entity Id
Xrm.Page.data.entity.getEntityName();//获取当前 Entity 的 Name

查询带出选项集的名称

var result = null;
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/xxxs(xxxx)", false);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
//核心语句
req.setRequestHeader("Prefer", "odata.include-annotations=OData.Community.Display.V1.FormattedValue");
req.send();
if (req.readyState === 4) {req.onreadystatechange = null;if (req.status === 200) {result = JSON.parse(req.response);} else {Xrm.Utility.alertDialog(req.statusText);}
};
console.log(result);

三、常用语句-字段

1.错误提示

Xrm.Page.getControl("lt_id").setNotification("该身份证号已被注册!", "IDCard2");
Xrm.Page.getControl("lt_id").clearNotification("IDCard2");

 2.字段值获取

Xrm.Page.getControl(sFieldName).getAttribute().getValue();

  取FormattedValue

entity["_scc_leadnum_value@OData.Community.Display.V1.FormattedValue"]  

3、在IFrame里面设置父页面字段上的值

parent.Xrm.Page.data.entity.attributes.get("new_tagselected").setValue("value");

4.字段控制

//给字段名为“name”的字段赋值后自动提交
Xrm.Page.getAttribute("name").setSubmitMode("Inputer");
//改变字段的字段需求  (注:required业务必选;none可选;recommended业务推荐)
Xrm.Page.getAttribute("字段名").setRequiredLevel("required"); 
//隐藏名为“st_portfoliomanager”的字段
Xrm.Page.getControl("st_portfoliomanager").setVisible(false);
//取消隐藏(显示)名为“st_portfoliomanager”的字段
Xrm.Page.getControl("st_portfoliomanager").setVisible(true);//锁字段名为“ownerid”的字段(注:页眉的字段加header_)
Xrm.Page.getControl("ownerid").setDisabled(true);
//解锁字段名为“ownerid”的字段  
Xrm.Page.getControl("ownerid").setDisabled(false);
//局部刷新(子网格也可以局部刷新)
Xrm.Page.getControl("st_customerneed").refresh();
//删除选项集中的选项 
Xrm.Page.getControl("字段名").removeOption("值");  
//添加选项集中的选项 
Xrm.Page.getControl("字段名").addOption(提前获取的缓存的选项);  

5.锁定所有字段

var controls = Xrm.Page.ui.controls.get();
for (var i in controls) {var control = controls[i];control.setDisabled(true);
}

6.日期类型字段处理

var myContactBirthday;
myContactBirthday = Xrm.Page.getAttribute("birthdate").getValue();
alert("Contact birthday is: " + myContactBirthday);
var year = myContactBirthday.getFullYear();
var month = myContactBirthday.getMonth(); // from 0 to 11
var day = myContactBirthday.getDate(); // from 1 to 31

7.自定义字段查找范围

var viewDisplayName = "xxx";
var entityName = "xxx";
var lookupControl = Xrm.Page.getControl("xxx");
var layoutXml = "<grid name='resultset' object='10013' jump='fullname' select='1' icon='1' preview='1'><row name='result' id='systemuserid'><cell name='fullname' width='300' /></row></grid>";
var id = '{xxx}';
var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'></fetch>";
lookupControl.addCustomView(id, entityName, viewDisplayName, fetchXml, layoutXml, false);
lookupControl.setDefaultView(id);

8、锁定属性

    /*** 锁定属性* @param {any} attributeName*/lockControlByAttributeName: function (attributeName) {let controls = Xrm.Page.getAttribute(attributeName).controls.getAll();if (controls) {for (con of controls) {con.setDisabled(true);}}}

四、常用语句-窗体

1.判断页面是否有修改

var formContext = null;
if (primaryControl !== null) {if (typeof primaryControl.getAttribute === 'function') {formContext = primaryControl; //called from the ribbon.} else if (typeof primaryControl.getFormContext === 'function'&& typeof (primaryControl.getFormContext()).getAttribute === 'function') {formContext = primaryControl.getFormContext(); // most likely called from the form via a handler}
}
var formIsDirty = formContext.data.getIsDirty();
// returns True for me when form is dirty 
if (formIsDirty) { return; 
}

2.错误提示

Xrm.Page.getControl("lt_id").setNotification("该身份证号已被注册!", "IDCard2");
Xrm.Page.getControl("lt_id").clearNotification("IDCard2");

3.获取窗体状态

//获取当前 form 的状态:
//0:Undefined 
//1:Create 
//2:Update 
//3:Read Only 
//4:Disabled 
//6:Bulk Edit 
var fromStatus= Xrm.Page.ui.getFormType();

4.弹窗提示

Xrm.Utility.alertDialog(this.statusText);

5.页面刷新

//页面刷新
Xrm.Utility.openEntityForm(Xrm.Page.data.entity.getEntityName(), Xrm.Page.data.entity.getId()
);
Xrm.Page.ui.refresh();
//页面保存并刷新
Xrm.Page.data.save().then(function () {parent.window.location.reload();}
);        

6.隐藏选项卡或节

//节隐藏
Xrm.Page.ui.tabs.get("tab_5").sections.get("tab_5_section_1").setVisible(false); 
//Tab隐藏
Xrm.Page.ui.tabs.get("tab_5").setVisible(false); 

7.新建跳转到实体并赋值

var customer= {};
//给新实体的”st_accountid“字段赋值
customer["st_accountid"] = Xrm.Page.data.entity.getId();  
customer["st_accountcount"] = 0;
//打开创建的记录
Xrm.Utility.openEntityForm("新实体名", null, customer);

8.使用指定窗体新建

var parameters= {};//给新实体的”st_accountid“字段赋值
parameters["st_accountid"] = Xrm.Page.data.entity.getId();       
parameters["st_accountcount"] = 0;
parameters["formid"]=窗体ID
//打开创建的记录
Xrm.Utility.openEntityForm("新实体名", null, customer);

9.阻止保存

function onload(){var eventArgs=context.getEventArgs();eventArgs.preventDefault();
}context.getEventArgs().preventDefault();//阻止保存操作

10.对Iframe或web窗体路径

function product_change() {var web = Xrm.Page.ui.controls.get("IFrame或web窗体名");var productid=Xrm.Page.getAttribute("st_productid").getValue();if(productid!=null){//DATA是要传的参数var params = "?DATA="+productid[0].id.replace('{', '').replace('}', ''); var newTarget = web +params;//传值web.setSrc(newTarget);    }
}  

确认弹框

//自定义弹框(确认/取消)
var confirmOptions = { height: 200, width: 450 };
var msg = { text: “message”, title: “title” };
Xrm.Navigation.openConfirmDialog(msg, confirmOptions).then(function (success) {if (success.confirmed) {}else{}
});

11.等待提示弹框

Xrm.Utility.showProgressIndicator("正在执行…");
Xrm.Utility.closeProgressIndicator();

12.lookup字段过滤

function shipToCustomView() {Xrm.Page.getControl("new_shiptoid").addPreSearch(shipToFilter);
}function shipToFilter() {var shiptoFilter;//客户代码var account = Xrm.Page.getAttribute("new_accountid").getValue();//销售公司var salescompany = Xrm.Page.getAttribute("new_salescompany").getValue();if (account == null || account[0] == null || salescompany == null || salescompany[0] == null)shiptoFilter = "<filter type='and'>"+ "<condition attribute='new_accountid' operator='eq' value='00000000-0000-0000-0000-000000000000' />"+ "<condition attribute='new_internalresourcesid' operator='eq' value='00000000-0000-0000-0000-000000000000' />"+ "</filter>";elseshiptoFilter = "<filter type='and'>"+ "<condition attribute='new_accountid' operator='eq' value='" + account[0].id + "'/>"+ "<condition attribute='new_internalresourcesid' operator='eq' value='" + salescompany[0].id + "'/>"+ "</filter>";Xrm.Page.getControl('new_shiptoid').addCustomFilter(shiptoFilter, 'LOOKUP实体name');
}

13.子网格设置指定列只读,使用子网格表onRecordSelect事件

function onrowselect(executionContext) {var entityObject = executionContext.getFormContext().data.entity;entityObject.attributes.forEach(function (attribute, i) {var control = attribute.controls.get(0);if (attribute.getName() == '需要锁定字段的名称') {control.setDisabled(true);}});
}

14.多窗体时跳转到指定窗体

var currentForm = Xrm.Page.ui.formSelector.getCurrentItem(); //获取当前窗体
if (currentForm != null) {if (currentForm.getLabel().toLowerCase() != formName.toLowerCase()) { //make sure it's not already this formvar availableForms = Xrm.Page.ui.formSelector.items.get(); //获取所有可选窗体for (var i in availableForms) {var form = availableForms[i];if (form.getLabel().toLowerCase() == formName.toLowerCase()) { //跳到指定名称窗体form.navigate();}}}
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com