Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Saturday, June 7, 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: Anyone have a copy of the Unaltered SaveOpportunity Code?
Wiley S.
Posts: 52
 
Anyone have a copy of the Unaltered SaveOpportunity Code?Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 06 Sep 12 11:38 AM
fiogf49gjkf0d

I am working on getting ou Opportunities working after being off this project for several months.


Currently they do not save correctly.  The opportunity saves but the address from the form does not save.


There is a relationship for the address table that should allow the save.


Does anyone have the original SaveOpportunity code handy that they can upload?


 


Here is mine which is failing...


 



namespace Sage.BusinessRules.CodeSnippets


{


    public static partial class OpportunityBusinessRules


    {


        public static void OnSave( IOpportunity opportunity)


        {


            // TODO: Complete business rule implementation



Sage.Entity.Interfaces.IAddress address = Sage.Platform.EntityFactory.Create<Sage.Entity.Interfaces.IAddress>();


            address.Address1 = opportunity.Address.Address1;


           address.Address2 = opportunity.Address.Address2;


           address.Address3 = opportunity.Address.Address3;


           address.Address4 = opportunity.Address.Address4;


           address.State = opportunity.Address.State;


           address.City = opportunity.Address.City;


            address.PostalCode = opportunity.Address.PostalCode;


           address.Country = opportunity.Address.Country;


           address.County = opportunity.Address.County;


           address.Routing = opportunity.Address.Routing;


            address.Salutation = opportunity.Address.Salutation;


           address.TimeZone = opportunity.Address.TimeZone;


           address.Type = opportunity.Address.Type;


           address.Description = opportunity.Address.Description;


            address.IsPrimary = opportunity.Address.IsPrimary;


            address.IsMailing = opportunity.Address.IsMailing;


            address.EntityId = opportunity.Id.ToString();


            address.Save();



opportunity.AddressID = address.Id.ToString();


 


opportunity.Save();


        }


    }


}


 


Thank you!!


[Reply][Quote]
Wiley S.
Posts: 52
 
Re: Anyone have a copy of the Unaltered SaveOpportunity Code?Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 10 Sep 12 4:26 PM
fiogf49gjkf0d

OK.  Well that is obviously a bust.


 


Can anyone show me how to accomplish the following?


 


I want to save an address for my opportunity.


It is a job site and is specific to the opportunity.


 


I have tried a relationship to Address with the code above.  It fails.


I have tried a separate table for the address with a relationship.  It fails.


 


You would think this would be simple.  What am I missing?


 


Thanks,


W


 

[Reply][Quote]
RJ Samp
Posts: 973
Top 10 forum poster: 973 posts
 
Re: Anyone have a copy of the Unaltered SaveOpportunity Code?Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 10 Sep 12 8:43 PM
fiogf49gjkf0d

You are not storing an Address.EntityId value......place the OpportunityId in there and see what happens. I often store other 'entities' addresses in the Address Table.....including Activity Address (where the Meeting was held).

[Reply][Quote]
Wiley S.
Posts: 52
 
Re: Anyone have a copy of the Unaltered SaveOpportunity Code?Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 11 Sep 12 10:51 AM
fiogf49gjkf0d

Hmmm... The last 3 lines set the EntityID and the AddressID.  Am I doing it wrong?


This is in a CodeSnippet and occurs during the Business Rule for SaveOpportunity.OnSave


Thank you!



W


 

[Reply][Quote]
Wiley S.
Posts: 52
 
Re: Anyone have a copy of the Unaltered SaveOpportunity Code?Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 11 Sep 12 10:55 AM
fiogf49gjkf0d

Also, my relationship is between AddressID in Address and AddressID in Opportunity.  


Does the EntityID field still play in with that as the relationship field?


 


Thanks,


W


 

[Reply][Quote]
RJ Samp
Posts: 973
Top 10 forum poster: 973 posts
 
Re: Anyone have a copy of the Unaltered SaveOpportunity Code?Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 11 Sep 12 12:00 PM
fiogf49gjkf0d

My bad, didn't see the EntitiId field being populated....


 


I've never done this on the WEB side of things.....for all you and I know we are running into some sort of business rule. However, you state you created a new 'OppAddress' table entity and it still doesn't work?


 


Do you have a relationship between Opp.AddressId and Address.AddressID, or is a 1:1 extension table property? Do you have a relationship between Opp.OpportunityId and Address.EntityId as well? are you displaying the results in a Grid (for a relationship), or fields (1:1 extension).


 


When you run your save routine, what are you getting out of SLX Profiler.....


 


I'm not in front of any code at present, but are you absolutely certain that your entity create statement is correct? There doesn't have to be a new clause in it for example.

[Reply][Quote]
Wiley S.
Posts: 52
 
Re: Anyone have a copy of the Unaltered SaveOpportunity Code?Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 11 Sep 12 1:12 PM
fiogf49gjkf0d

Did this to test...



Sage.Entity.Interfaces.IAddress address = Sage.Platform.EntityFactory.Create<Sage.Entity.Interfaces.IAddress>();


 


throw new Sage.Platform.Application.ValidationException(address.Id.ToString());


I get an error of Object Reference not Set to an INstance of an Object.


So I guess that is where the problem lies.  I should probably check to see if an Address exists and update or create based upon that.

I just have to figure out how that works in SageWorld.


[Reply][Quote]
Wiley S.
Posts: 52
 
Re: Anyone have a copy of the Unaltered SaveOpportunity Code?Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 11 Sep 12 3:01 PM
fiogf49gjkf0d

Is tehre a place where I can find code snippet examples?


Redmonds book isn't getting me there.


Thanks,


W

[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: Anyone have a copy of the Unaltered SaveOpportunity Code?Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 12 Sep 12 10:49 AM
fiogf49gjkf0d

The best place for examples is to break open Reflector and examine some of the out of the box business rules.

[Reply][Quote]
Wiley S.
Posts: 52
 
Re: Anyone have a copy of the Unaltered SaveOpportunity Code?Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 12 Sep 12 11:28 AM
fiogf49gjkf0d

Thanks Ryan!  That is what I did starting yesterday.  I have been looking through Leads for examples.


So far I am not havivng any luck.  I am considering just throwing the code into my assembly DLL I use for other stuff and calling it good.


It would be nice if I could just get it to work in the Snippet tho.  The task seems simple.


Hae an Address control on the Opportunity Detail page.  Save the Address to the Address table.


I should only need the relationship set to 1:M back to Address from Opportunity with SaveUpdateDelete, correct?


Then when the Business Rule for Opportunity Save fires, it should cascade down to the Addres field, correct?


Or do I have to custom code the whole process to get the address into Address and set it to the OpportunityID in EntityID?


Is my relationship correct in using AddressID on both table?  EntityID is not referenced.


 


Thank you!


Wiley


 

[Reply][Quote]
Wiley S.
Posts: 52
 
Re: Anyone have a copy of the Unaltered SaveOpportunity Code?Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 12 Sep 12 5:58 PM
fiogf49gjkf0d

No matter what I do, this code always fails...



address.EntityId = opportunity.Id.ToString();


How can that be?


 


[Reply][Quote]
Mark Dykun
Posts: 297
 
Re: Anyone have a copy of the Unaltered SaveOpportunity Code?Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 13 Sep 12 7:08 AM
fiogf49gjkf0d

What is the error when you try to set the Id. Are you certian that Opportunity.Id is a non null value. I would check if that is true or not before you assign the address to it. I would also be concerned but not sure currently if explicity calling Opportunity.Save in side of a OnSave event will cause recursion.

[Reply][Quote]
Wiley S.
Posts: 52
 
Re: Anyone have a copy of the Unaltered SaveOpportunity Code?Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 13 Sep 12 10:43 AM
fiogf49gjkf0d

Object Reference not Set to an INstance of an Object


 


Which makes no sense to me if we are passing the object in and it is accessible.


I think I am making progress tho.  I updated the OnCreate event to make a new Address and that seems to help.


Updated my relationship to be Address to Address field from Opp table to Address table basically mirroring how Account is setup to do that.


Now I can insert a address at Opportunity creation.  I am working on making it save a new address today when editing and none exists.





[Reply][Quote]
Mike LaSpina
Posts: 116
 
Re: Anyone have a copy of the Unaltered SaveOpportunity Code?Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 13 Sep 12 12:48 PM
fiogf49gjkf0d

Note that IDs are not populated until the record saves.  So, if you are referencing Opportunity.Id.ToString(), you will get that 'Object not set to an instance of an object' error in your code.  The problem with the entity ID in addresses on insert is that you end up in sort of a chicken and egg situation - you cannot set the Address.EntityId until AFTER you save the opportunity, but you want the cascade the address record when saving the opportunity.  Use the ORM to your advantage in this situation:


 



  • Create a 1:M relationship from Opportunity to Address (see the Account Address relationship for an example)

  • Create the address record for the opportunity and fill in the values:

    • IAddress a =  Sage.Platform.EntityFactory.Create<IAddress>();

    • a.Address1 = "123 Some St.";

    • ...



  • Make the association by object - not by ID, and save:

    • Opportunity.Address = a;

    • Opportunity.Save();



[Reply][Quote]
Wiley S.
Posts: 52
 
Re: Anyone have a copy of the Unaltered SaveOpportunity Code?Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 13 Sep 12 1:44 PM
fiogf49gjkf0d

Thanks Mike!


I did something similar initially.  I created my own BR to run on Save for Opportunity.


In that rule, i created a enw address and tried to set the EntityID from Opp.Id.


Trying to save without setting EntityID fresults in an error too.


Now I see why it failed.  Thank you!


https://picasaweb.google.com/102437815629000501356/SLXWork#5787733216635440338


My relationship for Opportunity to Address is a mirror of the one in Account.


Is is a Child in the realtionships for Opportunity called Address.


It is M:1 which is exactly how my Account to Address relationship looks.


Opp Add Relationship


Since then (yesterday), I have been working in the OnCreate, OnBeforeInsert, and OnBeforeUpdate events for Opportunity.


OnCreate - I create an associated Address record.  


OnBeforeInsert - I was getting a blank from opp.Id here but it was isnerting correctly


OnBeforeUpdate - grabbing the address by GetByID and updating.


 


 


 


 


 


 

[Reply][Quote]
Wiley S.
Posts: 52
 
Re: Anyone have a copy of the Unaltered SaveOpportunity Code?Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 13 Sep 12 1:52 PM
fiogf49gjkf0d

Should I dump all the On events and create a BusRule for the Save of Opportunity instead?


How would I get the values from the form entry in a C# CodeSnippet biz rule?


Do I access the relationship to get the values like so since Opportunity is being passed in?




  • IAddress a =  Sage.Platform.EntityFactory.Create<IAddress>();

  • a.Address1 = opportunity.Address.Address1;

  • a.Address2 = opportunity.Address.Address2;

  • a......... etc, etc

  • a.Save();


  • Opportunity.Address = a;

  • Opportunity.Save();



Does associating by ID take care of the EntityID field in Address that blows up if I try to save otherwise?



 


 

[Reply][Quote]
Mike LaSpina
Posts: 116
 
Re: Anyone have a copy of the Unaltered SaveOpportunity Code?Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 13 Sep 12 2:03 PM
fiogf49gjkf0d

Opportunity.Id will always be null in the OnBeforeInsert method. 


 


In your case, you may want to try using the OnAfterInsert method to create the address record.  The Opp id would be present at this time.  The bad news here is that you will have to issue another save for the Opportunity to save the address record, which will result in the firing of the OnBeforeUpdate and OnAfterUpdate rules. 

[Reply][Quote]
Wiley S.
Posts: 52
 
Re: Anyone have a copy of the Unaltered SaveOpportunity Code?Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 13 Sep 12 2:08 PM
fiogf49gjkf0d

BTW when I create the relationship as 1:M as a Child in Opportunity, I cannot see Opportunity.Addresses when I try to setup the Address control on Opportunity Details.


I have rebuilt all the Interfaces.  I can only see the relationship if I use M:1.

[Reply][Quote]
Wiley S.
Posts: 52
 
Re: Anyone have a copy of the Unaltered SaveOpportunity Code?Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 13 Sep 12 2:13 PM
fiogf49gjkf0d

OK.  Now I am thouroughly confused.


I dropped my On event method to test your ORM method.  Is the use of ORM not the ideal method?


I just want to have an Address on Opportunity Insert and Opportunity Update and save/udpate to Address table.


The link in my previous post show the relationship as it was when I was using the On events.


Here is what it looks like now since I changed it to how you said to do it through ORM.


https://picasaweb.google.com/102437815629000501356/SLXWork#5787741389412563714


 

[Reply][Quote]
Wiley S.
Posts: 52
 
Re: Anyone have a copy of the Unaltered SaveOpportunity Code?Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 13 Sep 12 6:24 PM
fiogf49gjkf0d

BTW - Sorry if the last sounded frustrated.  I just keep hitting dead ends and with only Redmonds book to get me there, I am running out of ideas.


Thank you for all the responses!


W

[Reply][Quote]
Yoyo
Posts: 7
 
Re: Anyone have a copy of the Unaltered SaveOpportunity Code?Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 19 Mar 13 5:23 AM

Hello Wiley,


I am working on a similar issue . So I read the comments and will try them but I wanted to know if you finally succeed and if yes how ?


thanks !!!

[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): 6/7/2025 10:51:53 PM