Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Saturday, April 27, 2024 
 
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: Add a button to call a url
Lee Owen
Posts: 46
 
Add a button to call a urlYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 04 Sep 07 9:36 AM
I need to add a button to call a url with one of the database values in the URL. Can anyone help me make a CSharp Code Snippet to call a URL with a Database value in the URL?

help!
[Reply][Quote]
Raul A. Chavez
Posts: 1300
Top 10 forum poster: 1300 posts
 
Re: Add a button to call a urlYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 04 Sep 07 9:53 AM
To Get the URL:

private string GetURL()
{
// I just wrote this directly on the browser, not sure if it will compile.
System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection();
conn.ConnectionString = myConnString

System.Data.OleDb.OleDbCommand CMD = new System.Data.OleDb.OleDbCommandstrSQL, conn);
conn.Open();

string url = CMD.ExecuteScalar().ToString();
CMD.Dispose();
CMD = null;

conn.Close();
conn.Dispose;
conn = null;
return url;
}


To launch the URL the easiest way is:

string URL = GetURL();
System.Diagnostics.Process.Start(URL);
[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: Add a button to call a urlYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 04 Sep 07 11:47 AM
You don't want to use Process.Start. Remember, this is server side code so it will attempt to start the process on the server under the ASPNET account, not on the client.
[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: Add a button to call a urlYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 04 Sep 07 11:53 AM
Quote:
Originally posted by Lee Owen

I need to add a button to call a url with one of the database values in the URL. Can anyone help me make a CSharp Code Snippet to call a URL with a Database value in the URL?


In the C# Snippet, you'll use Response.Redirect to redirect to the URL. If you want it to launch in a new window (instead of in the current SLX browser session) things will get a bit tricker. There's several ways to attempt this, but one way would be to edit the smartpart ascx file itself and add something where you can add the Url to an asp:Hyperlink control from the server side code. Then you can set a target for the link. If you don't want the user to have to click something, then you could emit javascript to the client from the server code to open the new window to the URL you want. Using Response.Write you could write out the javascript to the client. All this of course is theory, not something I've tried yet myself.

-Ryan
[Reply][Quote]
Raul A. Chavez
Posts: 1300
Top 10 forum poster: 1300 posts
 
Re: Add a button to call a urlYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 04 Sep 07 11:58 AM
I guess I need to pay more attention to what Forum I am replying to. I just read the request and quickly gave him a response.
[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: Add a button to call a urlYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 04 Sep 07 12:05 PM
Quote:
Originally posted by Raul A. Chavez

I guess I need to pay more attention to what Forum I am replying to. I just read the request and quickly gave him a response.


I've done that a time or two as well.
[Reply][Quote]
Lee Owen
Posts: 46
 
Re: Add a button to call a urlYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 04 Sep 07 12:57 PM
Ryan,
Thanks for the info. So I've opened my ContactDetail.ascx and added an asp:HyperLink control. It in fact makes a link for me. How would i populate the NavigateUrl value with the WorkPhone field from the database?
I'd like my final url to be http://mydeskphone/dial?number=WORKPHONEVALUEFROMDATABASE
Right now i have <asp:HyperLink runat="server" ID="QFButton" NavigateUrl="http://deskphone/dial?number=" Text="Dial" />
All that is missing is being able to call the database value in my HyperLink. Any help is greatly appreciated.

Lee
[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: Add a button to call a urlYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 04 Sep 07 1:17 PM
Hold the phone (pun intended ).

I thought of a much better way to do this that does not require modifying the ascx file directly (which would get overwritten when you redeploy). Do this insetad:

1) Open the Contact Details quick form under the Contact entity
2) Add a Button to the form (you could change this to also render a hyperlink or icon and select a phone image or something as well) and name it buttonDial
3) Create a LoadAction for the form and select C# Code Snippet for the Action
4) *IMPORTANT*. For the LoadAction, make sure you set "OnRepaintEvent" to True
5) In the C# code the action you can now set the OnClientClick property of the button. This property can contain javascript. You'll construct the URL in the LoadAction and then set the value from that property. Something like this:

Sage.Entity.Interfaces.IContact contact = this.BindingSource.Current as Sage.Entity.Interfaces.IContact;
if (contact != null)
{
buttonDial.OnClientClick = string.Format("window.open('http://mydeskphone/dial?number={0}');", contact.WorkPhone);
}


Make sense? That should work just fine. This is all untested of course, but should all work, let me know if it doesn't.

-Ryan
[Reply][Quote]
Lee Owen
Posts: 46
 
Re: Add a button to call a urlYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 04 Sep 07 2:26 PM
this looks helpful, unfortunately i'm now at a point where i can not deploy the portal. it tries to deploy and i don't get errors, but my files aren't overwritten. so i've gone in to the quick forms and added my button but when i build the site, my contact pages say 'Quick Form 'ContactDetails' built as \\Webroot\Common\SmartParts\Contact\ContactDetails.ascx.
I can find that location in the VFS explorer and find the files, but that isn't the location that i'm choosing to build to. I have no idea why my build started pushing files to this location rather than overwriting the files i had at d:\SLXClient. Any ideas on that?
[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: Add a button to call a urlYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 04 Sep 07 2:42 PM
I'm not sure I follow. It is supposed to build the SmartPart ascx files in \\Webroot\Common. You'll need to deploy after the build occurs. Are you doing that step?
[Reply][Quote]
Lee Owen
Posts: 46
 
Re: Add a button to call a urlYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 04 Sep 07 3:05 PM
yes. i make the change to my ContactDetail.ascx and save it. I then build the website, then i go deploy it. I did it 50 times and one finally worked. It made your click to dial code work. You're my hero! Then i tweaked it to fixup some details and i'm back to having trouble getting the deploy to overwrite it again. I build with no errors, then deploy with no errors but when i login, the page hasn't changed. ???? i've tried restarting IIS, recycling the Application Pool (which IISreset should have also done). Not sure why i can't consistently deploy the site.
Either way, your code seems to work if i can resolve my build troubles. I now need to just copy it and put buttons by each phone number on the form and I'm there.

Thanks for the help and let me know if you have any ideas on the deployment issues.

Lee
[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: Add a button to call a urlYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 04 Sep 07 3:18 PM
Glad it worked

I've not seen those sort of deployment problems before. Only idea I can think of to try is to hold down CTRL when you build (which forces it to rebuild everything) then deploy. You won't want to do that every time, but it is worth trying to see if that solves it.

BTW, a cool idea that I would do for this, replace ALL phone number fields with link buttons. This way, there is no second button to click, the phone number itself is a hyperlink. Change the ButtonType to Link. The Caption for the button is a bindable property, so you could bind the phone number to that so it displays as a hyperlink. Pretty cool. Also, doing it this way would make the phone number not be formatted, so you could make custom properties on the entity that take the number and apply the formatting to it and then use that to bind to the caption. For editing the numbers you could add a dialog to show all phone numbers for the entity in an editable form. Place a button somewhere to launch that (or just put that form in the tab workspace). That would be cool.
[Reply][Quote]
Lee Owen
Posts: 46
 
Re: Add a button to call a urlYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 04 Sep 07 4:03 PM
doing the build when holding CTRL seems to have solved my issues. Thanks for all of your help today.
[Reply][Quote]
Nick Hollis
Posts: 549
Top 10 forum poster: 549 posts
 
Re: Add a button to call a urlYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 05 Sep 07 2:27 AM
Hi Lee,

I get this problem a few times with deploying, if you delete the .ascx (from C:\Inetpub\wwwroot\slxclient etc etc) the deploy routine sees that its gone and it sends a new one...you really dont want to get into doing ctrl+build everytime, it will do your head in as its too time consuming!


Cheers,
Nick
[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: Add a button to call a urlYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 05 Sep 07 9:45 AM
Quote:
Originally posted by Nick

Hi Lee,

I get this problem a few times with deploying, if you delete the .ascx (from C:\Inetpub\wwwroot\slxclient etc etc) the deploy routine sees that its gone and it sends a new one...you really dont want to get into doing ctrl+build everytime, it will do your head in as its too time consuming!


Cheers,
Nick


Great idea Nick. Thanks for that.
[Reply][Quote]
fbw
Posts: 3
 
Re: Add a button to call a urlYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 24 Sep 08 5:13 PM
Slight twist on this same topic. How would you go about calling the url (which works fine as described) but ALSO changing the picklistvalue on another control on the form at the same time? Can't get it to work in the loadactions collection because there is no way to tell if the button has been clicked (that I know of...)

Any help is greatly appreciated. Thanks.
[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: Add a button to call a urlYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 24 Sep 08 5:23 PM
It might work to set both the click action of the button (which does the postback) to a business rule and also the OnClientClick to perform the client-side javascript. You'd have to try it, but that might do it.
[Reply][Quote]
fbw
Posts: 3
 
Re: Add a button to call a urlYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 25 Sep 08 2:14 PM
The OnClientClick performs the client-side javascript just fine, but can't get the business rule to work properly. I thought that standard practice was to set the click action of the button to "Refresh Data" and do the control manipulation (ie: pklStatus.PickListValue = "Closed - Won" in the load action of the form. That works fine if I have a condition to test on load action for a picklist change, etc but there is no way to know if the button was pressed. If I put the same code in a business rule and assign it to the click action nothing happens. Are there additional properties to set in order to force the form to refresh or is at simple as setting the click action to the business rule?

Thanks again for the help.
[Reply][Quote]
Stephen Redmond
Posts: 190
 
Re: Add a button to call a urlYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 25 Sep 08 7:39 PM
Hi,

I'm finding it difficult to follow the thread but, if I wanted to have a button that called a page with a particular field value, I would call a function in the Load event of the page that created a javascript function to do what I want. I would attach this code using RegisterClientScriptBlock. The function would look at the current value of a field (e.g. ctl00_MainContent_AccountDetails_MainPhone) and build the URL that I need. Then, my button on the form just needs to have an "OnClientClick" event to call this function.

I could be even lazier than that and just write a function for each entity that I wanted to use and put them statically in general.js.


Stephen
[Reply][Quote]
Lee Owen
Posts: 46
 
Re: Add a button to call a urlYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 05 Jan 09 10:22 AM
Quote:


Sage.Entity.Interfaces.IContact contact = this.BindingSource.Current as Sage.Entity.Interfaces.IContact;
if (contact != null)
{
buttonDial.OnClientClick = string.Format("window.open('http://mydeskphone/dial?number={0}');", contact.WorkPhone);
}



Ryan,
I"m using the C# code above to dial. I want to also do a lookup of the Country Code based on the users Country and append that Country code to my dialing string. Can you help me with the code to lookup the country dialing code based on the Contacts address?
[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: Add a button to call a urlYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 05 Jan 09 11:25 AM
Where do you need to lookup the country code from? You do have access to the contact's address via the contact object in the earlier code:

string country = contact.Address.Country;


What exactly do you need to do with the country value once you have it?
[Reply][Quote]
Lee Owen
Posts: 46
 
Re: Add a button to call a urlYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 05 Jan 09 11:39 AM
i need to take the country value, and do a lookup in to the country picklist to obtain the country dialing code. Then i need to append that value to the number i'm dialing so i send a dial string to my deskphone with CountryCode + PhoneNumber.
[Reply][Quote]
Lee Owen
Posts: 46
 
Re: Add a button to call a urlYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 08 Jan 09 8:08 AM
does anyone know the c# snippet code that would let me look up a contacts country, then look up the dialing code for their country from the country picklist and then append that dialing country code to the phone number string i'm passing to a URL?
HELP!!!
thanks for any insight anyone can provide.
[Reply][Quote]
willis
Posts: 22
 
Re: Add a button to call a urlYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 08 Jan 09 9:46 AM
Couldn't you just query the PICKLIST table using the country string value?

string country = contact.Address.Country;

Sage.Platform.Data.IDataService _dataService = ParentWorkItem.Services.Get();
string sql = "Select Shorttext from Picklist where Text = '" + country + "' and PicklistID = 'YOURPICKLISTID'";
using (System.Data.OleDb.OleDbConnection conn = (System.Data.OleDb.OleDbConnection)_dataService.GetConnection())
{
conn.Open();
}
string YOURURL = YOURURL + "Shorttext";
[Reply][Quote]
Lee Owen
Posts: 46
 
Re: Add a button to call a urlYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 08 Jan 09 11:50 AM
THANKS!
that's definitely getting me closer. i get this error:

error CS0411: The type arguments for method 'Sage.Platform.Application.ServiceCollection.Get()' cannot be inferred from the usage. Try specifying the type arguments explicitly.

i'm googling and trying to fix this but not having much luck so i figured i'd see if anyone had insight about how to address this error.


EDIT. I've narrowed it down to this line of code causing the error. still googling for a fix and tinkering with code.
Sage.Platform.Data.IDataService _dataService = ParentWorkItem.Services.Get();



[Reply][Quote]
willis
Posts: 22
 
Re: Add a button to call a urlYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 08 Jan 09 3:56 PM
Try this. Saw it on another post...

Sage.Platform.Data.IDataService _dataService = ParentWorkItem.Services.Get();
[Reply][Quote]
willis
Posts: 22
 
Re: Add a button to call a urlYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 08 Jan 09 4:00 PM
That is strange... that is not what I typed. Apparently the forum hides anything inside arrow brackets.

Should be a Sage.Platform.Data.IDataService inside the arrow brackets below...
Sage.Platform.Data.IDataService _dataService = ParentWorkItem.Services.Get<>();
[Reply][Quote]
Lee Owen
Posts: 46
 
Re: Add a button to call a urlYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 08 Jan 09 5:56 PM
Thanks Willis. That got me past that error. Now on to the next one. Obviously I'm not very good at this.

Here's my entire code snippet.

Sage.Entity.Interfaces.IContact contact = this.BindingSource.Current as Sage.Entity.Interfaces.IContact;

if (contact.Address.Country != null)
{
string country = contact.Address.Country;
Sage.Platform.Data.IDataService _dataService = ParentWorkItem.Services.Get<Sage.Platform.Data.IDataService>();
string sql = "Select Shorttext from Picklist where Text = '" + country + "' and PicklistID = 'Country'";
using (System.Data.OleDb.OleDbConnection conn = (System.Data.OleDb.OleDbConnection)_dataService.GetConnection())
{
conn.Open();
}
}
string YOURURL = YOURURL + "Shorttext";

if (contact != null)
{
DialButton4.OnClientClick = string.Format("window.open('http://mydeskphone/callback?n=" + YOURURL + "{0}');", contact.WorkPhone);
}




I get an error CS0165: Use of unassigned local variable 'YOURURL'
Can you help me finish this up and print out the value of YOURURL? You can see in my window.open event that i just want to open my deskphone url and pass n= TheValueYouHelpedMeFind and {0} which is workphone. So the value of n (number) in my url is this countrycode we've looked up plus the phone number. That way my phone dials the proper countries based on the contacts country value.
We do a lot of international dialing and we want this country code separate from the phone number string.

You've been a huge help and i'll keep digging on my own but i seem to just get more and more different errors as i tinker with the code. I'm hoping someone can help me solve this for good.



[Reply][Quote]
willis
Posts: 22
 
Re: Add a button to call a urlYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 08 Jan 09 9:12 PM
Sorry... forgot you need a sql command to generate the result. And you also need to define your result string before the using. So your code looks like this:

string YOURURL;
using (System.Data.OleDb.OleDbConnection conn = (System.Data.OleDb.OleDbConnection)_dataService.GetConnection())
{
conn.Open();
System.Data.IDbCommand cmd = conn.CreateCommand();
cmd.CommandText = sql;
YOURURL = cmd.ExecuteScalar().ToString();
}
}
if (contact != null)
{
DialButton4.OnClientClick = string.Format("window.open('http://mydeskphone/callback?n=" + YOURURL + "{0}');", contact.WorkPhone);
}
[Reply][Quote]
Lee Owen
Posts: 46
 
Re: Add a button to call a urlYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 12 Jan 09 8:04 AM
getting close.
still getting this error
error CS0103: The name 'YOURURL' does not exist in the current context

here is my complete snippet.


Sage.Entity.Interfaces.IContact contact = this.BindingSource.Current as Sage.Entity.Interfaces.IContact;

if (contact.Address.Country != null)
{
string country = contact.Address.Country;
Sage.Platform.Data.IDataService _dataService = ParentWorkItem.Services.Get<Sage.Platform.Data.IDataService>();
string sql = "Select Shorttext from Picklist where Text = '" + country + "' and PicklistID = 'Country'";


string YOURURL;
using (System.Data.OleDb.OleDbConnection conn = (System.Data.OleDb.OleDbConnection)_dataService.GetConnection())
{
conn.Open();
System.Data.IDbCommand cmd = conn.CreateCommand();
cmd.CommandText = sql;
YOURURL = cmd.ExecuteScalar().ToString();
}
}
if (contact != null)
{
DialButton4.OnClientClick = string.Format("window.open('http://mydeskphone/callback?n=" + YOURURL + "{0}');", contact.WorkPhone);
}
[Reply][Quote]
 Page 1 of 2Next > >> 
  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 © 2024 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): 4/27/2024 3:48:42 PM