Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Tuesday, July 1, 2025 
 
slxdeveloper.com Community Forums  
   
The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
 Web Forums - SalesLogix Web Platform & Application Architect
Forum to discuss the use of the SalesLogix Web Platform, Client and Customer Portals, and the Application Architect (For version 7.2 and higher only). View the code of conduct for posting guidelines.
Forums RSS Feed


 Back to Forum List | Back to SalesLogix Web Platform & Application Architect | New ThreadView:  Search:  
 Author  Thread: 7.5.2 - AddEdit Form - 'Inheriting' Values from Parent Entity
Phil Parkin
Posts: 819
Top 10 forum poster: 819 posts
 
7.5.2 - AddEdit Form - 'Inheriting' Values from Parent EntityYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 11 Jan 10 5:04 PM
This has been driving me mad for hours!

OK, I have a new entity, Project, which has Opportunity as its parent (one-to-many off Opportunity).

I have an Add button appearing in the Opportunity Projects tab (on Opportunity Detail). This displays a form and allows a new Opportunity Project record to be created - all works.

I have a Description field on the Project which I want to default, on creation, to the Description of the Opportunity. So I created an OnLoad CodeSnippet event:


public static partial class AddEditProjectEventHandlers
{
public static void OnLoad1Step( IAddEditProject form, EventArgs args)
{
IProject Project = form.CurrentEntity as IProject;

if (form.txtDescription.Text == "")
{
Project.Description = "Test";
}

}
}


That works. Sets the Project's description to 'Test' if it is currently blank. (By the way, checking (Project == null), which is the check I wanted to use for whether I was in Add mode, gave me an error)

But try as I may, using as many combinations of object hierarchies and GetParentEntity() as I could dream up (and as a maths graduate, that's quite a few), I could not get a reference to the parent Opportunity (and therefore to that Opportunity's Description). There must be a trick - please let me in on the secret.

Thanks
Phil

[Reply][Quote]
Nicolas Galler
Posts: 93
 
Re: 7.5.2 - AddEdit Form - 'Inheriting' Values from Parent EntityYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 11 Jan 10 10:19 PM
The GetParentEntity should work but it requires you to call up the dialog using the Child Insert Action
[Reply][Quote]
Phil Parkin
Posts: 819
Top 10 forum poster: 819 posts
 
Re: 7.5.2 - AddEdit Form - 'Inheriting' Values from Parent EntityYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 12 Jan 10 3:19 AM
Thank you Nicolas - if you mean 'Insert Child Dialog Action', I can confirm that I am running the code snippet off one of these. Or do you mean something else?

I have seen different constructs for using GetParentEntity() - I must admit, I don't understand where this function 'comes from' & this makes it all the more difficult to troubleshoot. Where is this function defined?

Many thanks
Phil
[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: 7.5.2 - AddEdit Form - 'Inheriting' Values from Parent EntityYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 12 Jan 10 8:46 AM
This function is defined in the EntityBoundSmartPart class, which all QuickForms inherit from, so the function is a part of the SmartPart. So, if you're accessing the parent entity in a C# Snippet action, then you can do this:

Sage.Entity.Interfaces.IMyParentEntity myparent = this.GetParentEntity() as Sage.Entity.Interfaces.IMyParentEntity;


If you're in a Code Snippet Action then you don't have access directly to the SmartPart so you can use the EntityContextService like this:

// Get a reference to the EntityContextServce
// and call GetEntity()
IMyParentEntity myparent = form.WorkItem.Services.Get<Sage.Platform.Application.IEntityContextService>().GetEntity() as IMyParentEntity;


Does that make sense?

-Ryan
[Reply][Quote]
Phil Parkin
Posts: 819
Top 10 forum poster: 819 posts
 
Re: 7.5.2 - AddEdit Form - 'Inheriting' Values from Parent EntityYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 12 Jan 10 11:04 AM
Thanks Ryan

I find it hard to imagine that I will ever come to grips with this object model!

It seems that you were close, but it did not compile. Here is my statement:


IOpportunity Opportunity = form.WorkItem.Services.Get<Sage.Platform.Application.IEntityContextService>().GetEntity as IOpportunity;


and here is the error:


ERROR - C:\Documents and Settings\Administrator\Application Data\Sage\Platform\Output\Sage.SnippetLibrary.CSharp\src\Sage.SnippetLibrary.CSharp
.@.e5b77290-96fa-460e-9d44-fc84885b55d5.codesnippet.cs(41,31):
Cannot convert type 'method group' to 'Sage.Entity.Interfaces.IOpportunity' via a reference conversion, boxing conversion, unboxing conversion, wrapping conversion, or null type conversion


Do you have any ideas?

Personally, I hope it's the unboxing conversion. Sounds like where you teach someone not to punch someone else. I'll need that after a few more hours with this stuff

Thanks again
Phil
[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: 7.5.2 - AddEdit Form - 'Inheriting' Values from Parent EntityYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 12 Jan 10 11:09 AM
"GetEntity" is a method call, so it needs the () at the end (you missed that part)

Like this:

IOpportunity Opportunity = form.WorkItem.Services.Get<Sage.Platform.Application.IEntityContextService>().GetEntity() as IOpportunity;


See the bold part towards the end.
[Reply][Quote]
Phil Parkin
Posts: 819
Top 10 forum poster: 819 posts
 
Re: 7.5.2 - AddEdit Form - 'Inheriting' Values from Parent EntityYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 12 Jan 10 11:49 AM
Beautiful, works a treat. Sorry for cocking up what you wrote in the first place.

This is going to take some learning. But already I can see the possibilities ... if only I knew how to write them and where to put them

Thank you
Phil
[Reply][Quote]
 Page 1 of 1 
  You can subscribe to receive a daily forum digest in your user profile. View the site code of conduct for posting guidelines.

   Forum RSS Feed - Subscribe to the forum RSS feed to keep on top of the latest forum activity!
 

 
 slxdeveloper.com is brought to you courtesy of Ryan Farley & Customer FX Corporation.
 This site, and all contents herein, are Copyright © 2025 Customer FX Corporation. The information and opinions expressed here are not endorsed by Sage Software.

code of conduct | Subscribe to the slxdeveloper.com Latest Article RSS feed
   
 
page cache (param): 7/1/2025 8:05:29 AM