How To Display popup message

Upon opening a grid App I need to display popup message and redirect user based on the condition.
I tried this code in "ScriptInit’ event but it does not work

if ([glo_companyid] == 0){
    sc_error_message("No Company Selected");
    sc_redir(admin_menu.php, "", "_parent");
} elseif ([glo_customerid] == 0) {
    sc_error_message("No Customer Selected");
    sc_redir(admin_menu.php, "", "_parent");
}    else {
    sc_error_message("It is Ok");
}    


I’m not sure if sc_error_message is supported in the init event, but the main issue is the sc_redir behind. That will cause the application to switch immediately causing the webbrowser to change page. So the popup is in the wrong context then and will never appear. To do something similar create a control application with an errormessage field. Then you could do something like:

[glob_jumpto]=‘admin_menu.php’;
[glob_errm]=’"no company selected’;
sc_redir(‘jumptocontrol’);

In the onrecord of the jumpcontrol you can set your errormessage variable to the [glob_errm]
In the onvalidate of the jumptocontrol you can set:

sc_redir([glob_jumpto];

You can make this mechanism more intelligent by not generating an errormessage but jump to the application to select your company and/or customer. In that case these applications will have to check if there’s something in the glob_jumpto and jump back to the original application if it applies or do nothng if the application is used stand-alone. That way - suppose the nothing has been selected - your application will first jump to select company, next it will jump to select customer and then continue. Just like the old basic subroutine way :wink:

hope this helps.

Thanks Albert.
Your suggestion with extra selection (through Control App) will not work. I need to assign toe variables (companyID and customerID) globally and do all other operations based on the two. Therefore I need to keep them in global variables. When opening a grid I just need to check if the 2 Var’s are not empty and if so popup a message then redirect user to selection screen.

As you see nothing fancy. The code above should work and if the messaging does not work that means SC is missing some macros to allow to do things like that. As a matter of fact to more I work with SC I’m finding more and more missing embed points which should be implemented. I think adding extra hooks should not be that hard. When working with Clarion (for example) I have about 50 embed point just for a single form procedure so I can place my code exactly where I want (when generated).

I have a grid App that starts from the search before the grid is displayed. I placed this testing line into SctiptInit event and it doesn’t seem to do anything

sc_error_message("TEST");

any idea ?
I wonder is SC_error_message works at all with the grid app (the Help states it works only with control and form apps, although I do not see why it would not work with the grid as well.

ARTHUR

Display message is marked RED when you are in an OnScriptInit which means that you can not use it there. This one actaully uses sc_error_message (AFAIK) so that makes sense.
You can of course alsways use echo “alert(‘my error message’)”; in your code in OnScriptInit.

I think that it would be great if SC had a special macro or app type for displaying proper pop up messages. Even the sc_alert and sc_error_message, where they can be used, look very bare bone, generic and boring compared to all the UI tweaking possibilities in the applications. In fact, the message looks like it is generated by the browser and has nothing to do with SC.

My background is in desktop and database development and so I am somewhat new to web development. Thus I do not know much about JavaScript/JQuery and such yet. But would it not be possible to have a proper pop up message window which could have theme, header, text, reply buttons and user input with with return values configured through JavaScript/JQuery, so that one would not have to leave the current page? When getting the return value from the message box, there could be an option to refresh the active application if needed, but for just validation and giving the user some information, it would not be necessary.

To me, it seems that the message capability in SC is totally out of sync with the high level of the other application types.

If you are not that much into web development I suggest you run yourself through w3schools this should help you a lot.
For that you will find interesting:
learn javascript, learn jquery, learn html (less usefull but you still need it), learn php (a must!)
That should give you a good start. By the way you can of course just use:
echo ‘alert(“this is a serious error you have made now”)’; in php (the alert… stuff is javascript.)

Thanks for the suggestions.
I guess that I am not that new to it as by now as I do have a fundamental, working knowledge of HTML and CSS. Coming from a C# background, PHP has been like stepping into pair of boots and just start walking. I have build several PHP classes that I use together with SC for background non-UI stuff. However, I have not really gotten started with JavaScript and JQuery, but I will certainly heed your advice and tug in. They do seem to be essential to get the full out of SC.

I do, nevertheless, still think that SC should do something about the lack of messaging capabilities, so that users from the get go can have better and more nice looking messaging, i.e. themed like the apps and with headers, etc. so they look and feel part of the full application.

OK, SC_error_message does work in Control App but it does not in Grid - what a disappointment!

As to the messaging - after studying the Macro list I could say that messaging and user interaction through messages does not exist in SC. I am under the impression that to be really productive we need about 100 new Macros and another 100 new Embed Points (read - Events)