Sage 100

 View Only
Expand all | Collapse all

Display Value on Panel

  • 1.  Display Value on Panel

    Posted 08-21-2019 12:33
    Scripting experts: What is THE way to display a value (calculated in script) on a panel without being prompted to save? 

    This should be a simple customization: display the gross profit % in Item Maintenance/Inquiry based on Last Cost and Standard Price.

    Why in the world can't we have the ability to change the text on a label?  

    The closest I have been able to get is using a button (that looks hideous for a method to display a value!)

    Unfortunately, that doesn't seem to be perfect either.

    When scrolling through records, the text on the button does not change (randomly it seems). The item where it doesn't change, WILL display if you choose it from the ALE, but every time I scroll through, this record(s) does not change the text.

    I have searched and searched (the search here really does suck, btw) and have found no definitive answer. 

    @David Speck II mentioned in an old Sage City post to use UDF set as borderless and locked. While this method does avoid the save prompt, it also makes the value invisible. (You can see the value flash in the location it is placed, but then it hides.) 

    Using a UDF does always display the value, but of course that method triggers a save prompt (even in inquiry!). 

    Any pointers to a definitive posting will be most appreciated. 



    ------------------------------
    Eric Lunceford
    First Mate Business Solutions
    Oklahoma City, OK
    877-880-8960
    https://www.firstmatellc.com/
    ------------------------------


  • 2.  RE: Display Value on Panel

    Posted 08-21-2019 12:40
      |   view attached
    I've attached a copy of @David Speck II's instructions to do this...​

    ------------------------------
    Kevin Moyes
    Technical Systems Analyst
    Munjal White Consulting Co.
    Toronto ON
    ------------------------------



  • 3.  RE: Display Value on Panel

    Posted 08-21-2019 14:06
    Thank you, Kevin (and David).

    That's a nice trick. 

    Unfortunately, this produces even more random results.

    Scrolling through records shows 0 for several records, then suddenly a correct value, which now sticks until another one calculates. Scrolling back sometimes triggers a correct calc, which then sticks for a number of records going backwards. 

    Selecting from ALE does the same thing. 


    ------------------------------
    Eric Lunceford
    First Mate Business Solutions
    Oklahoma City, OK
    877-880-8960
    https://www.firstmatellc.com/
    ------------------------------



  • 4.  RE: Display Value on Panel

    Posted 08-22-2019 00:20
    The trick with the ="calculate text here" in the text is really only useful on panels that are launched from an existing record, like a dialog panel as the formula is evaluated when the text is drawn which happens during the panel post load event.
    If you need to update a value during the reading of records like you said, you can either use a UDF as a placeholder and set it to borderless and locked on the panel but you need a script on the post read event to set it's value like this.
    Replace the contents in the bracket with the appropriate values.
    If oScript.UIObj > 0 Then oSession.AsObject(oScript.UIObj).SetControlProperty [UDF_Name], "Value$", [value you want displayed]


    ------------------------------
    David Speck II
    Tennessee Software Solutions
    ------------------------------



  • 5.  RE: Display Value on Panel

    Posted 08-22-2019 14:27
    I ended up using the button method and making the event script also work tied to the button so if they are scrolling and don't see the value, they can click the button and it calculates and displays on the panel. 

    David, when I tried your method, the value wouldn't display:

    @David Speck II mentioned in an old Sage City post to use UDF set as borderless and locked. While this method does avoid the save prompt, it also makes the value invisible. (You can see the value flash in the location it is placed, but then it hides.)

    I really do wonder why Sage is unable to expose a Text property for a text control. There must be a super technical reason.....

    ------------------------------
    Eric Lunceford
    First Mate Business Solutions
    Oklahoma City, OK
    877-880-8960
    https://www.firstmatellc.com/
    ------------------------------



  • 6.  RE: Display Value on Panel

    Posted 08-22-2019 15:06
    I didn't think about this before but if you use the calculated text and in a post read, force a post load of the panel, this should in theory redraw the text.

    ------------------------------
    David Speck II
    Tennessee Software Solutions
    ------------------------------



  • 7.  RE: Display Value on Panel

    Posted 08-22-2019 15:10
    How do you force a UI event?

    ------------------------------
    Kevin Moyes
    Technical Systems Analyst
    Munjal White Consulting Co.
    Toronto ON
    ------------------------------



  • 8.  RE: Display Value on Panel

    Posted 08-23-2019 00:13
    Edited by David Speck II 08-23-2019 00:15
    Alright, got a solution for this that appears reliable even on v2018.
    Use Customizer to modify the panel where you need the value displayed. 
    Click the Add Field button and then click somewhere on the panel to trigger the udf selection prompt.
    Click Show All.
    Locate a field that says "Display-Only". If you can't find any in the "MAIN" folder (usually the key field is available for this purpose if you haven't put it elsewhere), expand the next folder in the list. 
    Add the first field and take note of the field name. It should start with "ALB_MAIN_".
    Add the following code to the post load event for the panel where the udf was added and the tables post read event. Make sure to replace the field name and variables used in your implemention of this code. The important piece that must remain the same is the first argument of "SetVar". The field name following the "X" must match the udf name that you added to the panel.
    sItemCodeDesc = "" : oBusObj.GetValue "ItemCodeDesc$", sItemCodeDesc
    If oScript.UIObj > 0 Then oSession.AsObject(oScript.UIObj).SetVar "CMD_STR$", "X ALB_Main_ItemCode$=""" & Replace(sItemCodeDesc, """", """""") & """"

    The first line of the code is not important, it just happens to be the piece of data that i wanted to set into this field added to the panel, you can replace the first line with whatever logic it takes to get the value that you want to set into the field added to the panel. Just make sure to reference the correct variable name in the second line.
    The second line of code checks to see if the UI is present for this task, this is important in the post read event. It then uses the UIObj's SetVar method which is similar to the oBusObj's SetValue. The variable that we are setting is the CMD_STR$ variable that is local to the UI object and when it has valid providex code, it will be evaluated and executed depending on the very first character placed in the variable, in this case, we are setting the first character to "X" which tells the UI object to "EXECUTE" the rest of the string. The rest of the string is assigning whatever value you want to write to the field added to the panel to the variable for that control which is local to the UI object. In this case, the variable for the display only udf that i added is ALB_Main_ItemCode$, make sure to replace this with the correct field name displayed in Customizer's status bar. Also, double quotes in the value you want to assign have to be escaped before assigning it. This is what the [Replace(sItemCodeDesc, """", """""")] code is doing. Again, just replace the sItemCodeDesc variable with whatever variable name you decide to use.
    Hope this helps.

    EDIT:
    The reason for using the Display-Only fields is because they are automatically excluded from the record validation routine that checks for fields that have changed, making them ideal for this purpose since they won't trigger the prompt to save.



    ------------------------------
    David Speck II
    Tennessee Software Solutions
    ------------------------------



  • 9.  RE: Display Value on Panel

    Posted 08-23-2019 16:21
    You da man, David! 

    Works in 2019.1 as well. 


    ------------------------------
    Eric Lunceford
    First Mate Business Solutions
    Oklahoma City, OK
    877-880-8960
    https://www.firstmatellc.com/
    ------------------------------



  • 10.  RE: Display Value on Panel

    Posted 08-23-2019 16:32
    Edited by David Speck II 08-24-2019 04:31
    Glad it worked for you.
    In previous versions, i think maybe 2016-, the methods mentioned before worked but something seemed to have changed with the order in which the table post read events were firing and when values were being exploded from the IOList into the various controls on a given panel and i believe this is what causes the value to display briefly only to be overwritten again by whatever value was in IOList for the particular column.
    So using the UI object's CMD_STR$ variable makes sure the command is processed afterwards.
    I think at one point, i was using perform logic to use provideX code to add my own multi-line control to a panel either over top of a placeholder UDF added so i could reference its position or hardcoding the position and then used a post read to maintain the value and since it wasn't part of the IOList tracked by the _svc or _bus object i didn't have to worry about it trigger a save prompt or being overwritten by the IOList. This method required more lines of code and was more of hassle to repeat for more than one piece of info that you wanted to display.

    ------------------------------
    David Speck II
    Tennessee Software Solutions
    ------------------------------



  • 11.  RE: Display Value on Panel

    Posted 08-24-2019 03:18
    For additional coverage of various methods, Alnoor had a good idea in this post.
    https://www.sagecity.com/support_communities/sage100_erp/f/sage-100-personalization-customization-and-productivity-tools/110657/dynamic-programatically-set-values-in-customizer-text-object

    I also go over several methods in two answers in this post.
    https://www.sagecity.com/support_communities/sage100_erp/f/sage-100-personalization-customization-and-productivity-tools/108095/display-a-calculated-value-not-a-udf-on-a-customized-window/347939#347939

    ------------------------------
    David Speck II
    Tennessee Software Solutions
    ------------------------------



  • 12.  RE: Display Value on Panel

    Posted 08-24-2019 04:08
    Edited by David Speck II 08-24-2019 04:35
      |   view attached
    Felt like tinkering some more with the provideX 'Text' and 'Image' mnemonics method and came up with a good routine.
    The attached script contains two methods for illustrative purposes. 
    Method 1 uses a sourced display-only UDF as the placeholder for your dynamic value.
    Method 2 dynamically draws text on the screen. This is more flexible with positioning, font style, font size, and font, color.
    The script still needs to be attached to the table post-read and UI post-load if you want the dynamic text displayed consistently when a record is read and when the user switches tabs.
    ' Make sure "Allow External Access" is checked.
    If IsObject(oSession) Then
    	' Make sure task's UI object is present. 
    	' You can also add a check for the SY_Session.StartProgram property if you want to further restrict this to a specific task.
    	If oScript.UIObj > 0 Then
    		' Check the current folder name to make sure this executes while on the correct tab. 
    		' You can also add a check for oScript.GetScreenName() to further restrict this to a specific panel library.
    		If UCase(oSession.AsObject(oScript.UIObj).GetFolderName()) = UCase("pAddl") Then
    			' Get the value you want to use.
    			sItemCodeDesc = "" : oBusObj.GetValue "ItemCodeDesc$", sItemCodeDesc
    			
    			' Method 1, use a sourced display-only udf. Double quotes must be escaped by doubling them up.
    				oSession.AsObject(oScript.UIObj).SetVar "CMD_STR$", "X ALB_Main_ItemCode$=""" & Replace(sItemCodeDesc, """", """""") & """"
    				
    			' Method 2, use fonted text with a 'Image' group. You need to specify coordinates and can also change the color too. Double quotes must be escaped by doubling them up.
    				oScript.Execute "Print 'Image'(Delete ""sItemCodeDescText"")"
    				If sItemCodeDesc <> "" Then
    					oScript.Execute "sItemCodeDescText$='Red'+'Text'(@X(47),@Y(24.5),""" & Replace(sItemCodeDesc, """", """""") & """)"
    					oScript.Execute "Print 'Image'(""sItemCodeDescText""),sItemCodeDescText$"
    				End If
    		End If
    	End If
    End If​


    ------------------------------
    David Speck II
    Tennessee Software Solutions
    ------------------------------

    Attachment(s)

    zip
    SetDynamicText.zip   808 B 1 version