如何保存记录并立即使用其GUID [英] How to save a record and immediately use its GUID

查看:64
本文介绍了如何保存记录并立即使用其GUID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过功能区按钮执行一些javascript,我想要做的是保存我正在创建的记录,然后立即将其GUID用于其他代码。每次尝试保存GUID时,即使我要求GUID,GUID都返回null。如果我在保存按钮后再次尝试该按钮,则它可以工作,但不能保存。

I'm executing some javascript from a ribbon button and what I want to do is save the record that I am creating and then immediately use its GUID for some code a bit further on. Each time I try it the GUID is coming back null even though I'm requesting it after the record has been saved. If I try the button again after I've saved it then it works, but not as I'm saving it.

有没有办法做到这一点?

Is there a way to do this?

function RibbonButton_AddProduct()
{
  //Save the Record
  Xrm.Page.data.entity.save();

  LoadProductCreate();
}

function LoadProductCreate()
{
  var serverUrl;
  var errorMessage = "Context to retrieve the Server URL is not available.";
  if (typeof GetGlobalContext != "undefined"){
     serverUrl = GetGlobalContext().getServerUrl();
  } else {
  if (typeof Xrm != "undefined"){
    serverUrl = Xrm.Page.context.getServerUrl();
  } else {
    alert(errorMessage);
    return;
  }
}
if (serverUrl.match(/\/$/)){
   serverUrl = serverUrl.substring(0, serverUrl.length - 1);
}     

var recordId = Xrm.Page.data.entity.getId();

alert(recordId);
var url = serverUrl + "/main.aspx?etc=10030&extraqs=%3f_CreateFromId%3d%"+recordId
  +"%257d%26_CreateFromType%3d10029%26etc%3d10030%26"
  +"pagemode%3diframe%26preloadcache%3d1345465354543&pagetype=entityrecord";
window.open(url);
}


推荐答案

这是解决问题的另一种方法这个问题。

Here’s a different approach to solving this problem.

您要尝试做的是针对系统工作-您实际上在制作两个保存按钮。在Crm的其余部分中,当功能区按钮需要ID时,必须首先保存记录。例如。您不能在未保存的记录上使用对话框或工作流程按钮,也不能在未保存的记录中添加新的/现有的。

What you are trying to do is ‘working against the system’ - you are effectively making two save buttons. In the rest of Crm when the Id is required for a ribbon button the record must first be saved. E.g. you can’t use the dialog or workflow buttons on an unsaved record, you also can’t 'add new/existing' to an unsaved record.

所以我的解决方案是禁用未保存表单上的按钮,强制用户手动保存记录,然后允许他们使用您的按钮-这就是Crm的方式

So my solution would be to disable the button on unsaved forms, force the user to save the record manually and then allow them to use your button - this is the way Crm is meant to be used, and is the way the rest of Crm will work.

您不应该在系统上工作,而应该使用它,并且有一个产品定制和扩展–无需更改。

You should not work against the system, you should work with it, you have a product to customise and extend – not change.

如果这不符合您的要求,我建议使用Greg建议的带有标志的建议(1),尽管听起来有些混乱-但这是本质上的要求。

If this doesn’t meet your requirement I would suggest uses Greg’s suggestion (1) of having flags, though it sounds a bit messy - but then this is a requirement that inherently is.

这篇关于如何保存记录并立即使用其GUID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆