Skip to content

Commit

Permalink
Fixing bug or calling from other tool
Browse files Browse the repository at this point in the history
  • Loading branch information
rappen committed Jul 23, 2022
1 parent 4e7343f commit 6803be6
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions XRMTokensRun/XRMTR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public partial class XRMTR : PluginControlBase, IGitHubPlugin, IPayPalPlugin, IM
private const string aiEndpoint = "https://dc.services.visualstudio.com/v2/track";
private const string aiKey = "eed73022-2444-45fd-928b-5eebd8fa46a6"; // jonas@rappen.net tenant, XrmToolBox
private AppInsights ai = new AppInsights(aiEndpoint, aiKey, Assembly.GetExecutingAssembly(), "XRM Tokens Runner");
private EntityReference loadingreference;

public event EventHandler<MessageBusEventArgs> OnOutgoingMessage;

Expand Down Expand Up @@ -112,7 +113,13 @@ private void LoadEntitiesEtc()
entities = result;
cmbTable.DataSource = entities;
record.Service = Service;
if (settings.Table != null)
if (loadingreference != null)
{
cmbTable.SetSelected(loadingreference.LogicalName);
LoadRecord(loadingreference);
loadingreference = null;
}
else if (settings.Table != null)
{
cmbTable.SetSelected(settings.Table);
}
Expand Down Expand Up @@ -187,19 +194,19 @@ private void btnGetRecord_Click(object sender, EventArgs e)
};
if (look.ShowDialog() == DialogResult.OK && look.Record != null)
{
LoadRecord(look.Record.LogicalName, look.Record.Id);
LoadRecord(look.Record.ToEntityReference());
}
Enable(true);
}

private void LoadRecord(string entity, Guid id)
private void LoadRecord(EntityReference reference)
{
WorkAsync(new WorkAsyncInfo
{
Message = "Loading record...",
Work = (work, args) =>
{
args.Result = Service.Retrieve(entity, id, new ColumnSet(true));
args.Result = Service.Retrieve(reference.LogicalName, reference.Id, new ColumnSet(true));
},
PostWorkCallBack = (arg) =>
{
Expand Down Expand Up @@ -379,8 +386,16 @@ public void OnIncomingMessage(MessageBusEventArgs message)
if (!string.IsNullOrWhiteSpace(entity) && Guid.TryParse(idstr, out Guid id))
{
SetBackTag(message.SourcePlugin);
cmbTable.SetSelected(entity);
LoadRecord(entity, id);
var reference = new EntityReference(entity, id);
if (entities == null)
{
loadingreference = reference;
}
else
{
cmbTable.SetSelected(entity);
LoadRecord(reference);
}
}
else
{
Expand Down

0 comments on commit 6803be6

Please sign in to comment.