#GPPT Beginner’s Guide to Adding Custom Fields – Using the data


David Meego - Click for blog homepageWelcome to the fourth article in the series of articles that explain in detail the steps to add a user defined custom field to a window using Modifier, Report Writer and GP Power Tools to add the business logic.

The series should be read in order starting with the introduction article:

In this article we will use GP Power Tools to add the business logic to make the URL field work. We will make the hidden button open the URL in a browser window and add http:// at the beginning of the URL field if it is not added by the user.

For the business example we are working through, we need to add an internet URL field to the Item Maintenance window which can be opened in an internet browser.

The process to do this can be broken down into 6 Steps:

  1. Modifying the Window; Use Modifier to add the URL field to the Item Maintenance window with a hyperlinked prompt.
  2. Saving the Data; The data will be stored in the DUOS (Dynamic User Object Store) SY90000 table and business logic will be added to handle saving the URL field.
  3. Using the Data; Make the hyperlink open the URL in a browser window.
  4. Creating the Report Writer Function; Use Power Tools to create a Report Writer Function to allow the data to be pulled into reports.
  5. Modifying the Report; Use Report Writer to add a calculated field to call the Report Writer Function.
  6. Publishing the Project; Change settings to make the project available to all users.

Follow the steps below to complete Step 3: Using the Data, to make the hyperlink work to open the URL in a browser window. We will be adding two more triggers to our ITEM URL Project in GP Power Tools. (Click on images to see full sized versions and full scripts are listed at the end of the article).

  1. Open the Project Setup window to the ITEM URL project (it should open automatically as it was previously marked as the current project).
  2. Select Add >> Trigger Setup. If you get a dialog because the triggers are still registered, select Yes to unregister them and continue on to the Trigger Setup.
  3. On the Trigger Setup window, create a new trigger with the Trigger ID as ITEM URL FIELD, Trigger Description: Field Change Web URL Link field on Item Maintenance Window. Check the Start Trigger Automatically, Do not activate Logging and Minimize Log Entries checkboxes. Click on the Users Button and limit the trigger to only start for your User ID and click OK.
  4. We need a trigger on the custom field we added with Modifier, so set the Trigger Type: Focus Event, Trigger Event: Field Change, Trigger Attach: After Original. We can then use the by menu lookup (left hand of two lookup buttons) on the Resource tab to select Form Name: IV_Item_Maintenance, Window Name: IV_Item_Maintenance and Field Name: <Any Local Field>. Then select the Modified checkbox and change the Field Name to ‘(L) URL’. Press tab and if asked to reset the script, select Yes.
  5. No changes will be needed on the Actions tab and because we added the trigger from the Project Setup window, the Project ID is already entered on the Options tab. We just need to add code to the Script tab. Click on the Script Tab and ensure the Modified checkbox is selected and that the Check Security checkbox is selected.
  6. Make some space above the OUT_Condition, TRUE_STRING line so we can add some additional code to add http:// or https:// to the start of the URL if it is missing. We can copy the name of the field to the clipboard from the line above from the inside of the empty() function.
  7. Add the following lines to check for and add http:// or https:// as needed and indent them to the correct position. You can copy the final script from the bottom of this article if that is easier.
    { If not prefixed with http:// or https:// add http:// }
    if upper(substring('(L) URL' of window IV_Item_Maintenance of form IV_Item_Maintenance, 1, 7)) &lt;&gt; upper("http://") and
    upper(substring('(L) URL' of window IV_Item_Maintenance of form IV_Item_Maintenance, 1, 8)) &lt;&gt; upper("https://") then
    	'(L) URL' of window IV_Item_Maintenance of form IV_Item_Maintenance = 
    			substring("http://" + '(L) URL' of window IV_Item_Maintenance of form IV_Item_Maintenance, 1, 100);
    else
    	{ If prefixed with http:// or https://, then check it is lower case and update if needed }
    	if substring('(L) URL' of window IV_Item_Maintenance of form IV_Item_Maintenance, 1, 5) &lt;&gt;
    		lower(substring('(L) URL' of window IV_Item_Maintenance of form IV_Item_Maintenance, 1, 5)) then
    		'(L) URL' of window IV_Item_Maintenance of form IV_Item_Maintenance = 
    			lower(substring('(L) URL' of window IV_Item_Maintenance of form IV_Item_Maintenance, 1, 5)) +
    			substring('(L) URL' of window IV_Item_Maintenance of form IV_Item_Maintenance, 6, 
    				length('(L) URL' of window IV_Item_Maintenance of form IV_Item_Maintenance)-5);
    	end if;
    end if;
    
    
  8. Then press Ctrl-S to save and check syntax. If you have no errors then we can create the second of the two additional scripts.
  9. Click Duplicate and set the Trigger ID for the new trigger to ITEM URL BUTTON and click OK.
  10. Change the Trigger Description to Field Change Zoom Button on Item Maintenance Window. Then click on the Resource tab and change the Field Name to ‘(L) Zoom Button’ and press Tab. Select Yes to clearing the script when the dialog is displayed.
  11. Click on the Script Tab. Add some blank lines above the OUT_Condition, TRUE_STRING line and change empty(‘(L) Zoom Button’ of …. to empty(‘(L) URL’ of …. so that the actions of opening a browser window only occurs if the field has data in it. Again, we can copy the name of the field to the clipboard from the line above from the inside of the empty() function.
  12. Add the following lines to open a browser window and indent them to the correct position. You can copy the final script from the bottom of this article if that is easier.
    if IsWebClient() then
    	Utility_LaunchUrl('(L) URL' of window IV_Item_Maintenance of form IV_Item_Maintenance);
    else
    	run application "", '(L) URL' of window IV_Item_Maintenance of form IV_Item_Maintenance;
    end if;
    
    
  13. Then press Ctrl-S to save and check syntax. If you have no errors the Click Save.
  14. Close the Trigger Setup window and return to the Project Setup window.

So now we can test the customization again. Select Start >> Start Project Triggers from the toolbar of the Project Setup window. Then open the Modified version of the Item Maintenance window.

Pull up an item and enter in a URL (without the http:// prefix) and it shold get the prefix added when you tab off the field. Then click on the hyperlinked prompt and it should open a browser window to the URL. So now the new field is fully functional for both Desktop and Web Client.

Note: Adding Dexterity based triggers against custom fields added by Modifier is only possible with GP Power Tools and cannot be achieved with standard Dexterity alone.

In the next article we will work on the first of the two steps to getting the custom URL field showing on a report.

Below are the scripts from the two additional triggers:

ITEM URL FIELD Trigger Script

local boolean err_val;
local string IN_OldValue;
local string IN_NewValue;

err_val = OLE_GetProperty("IN_OldValue", IN_OldValue);
err_val = OLE_GetProperty("IN_NewValue", IN_NewValue);

err_val = OLE_SetProperty("OUT_Condition", FALSE_STRING);

if isopen(form IV_Item_Maintenance) then
	if not empty('(L) URL' of window IV_Item_Maintenance of form IV_Item_Maintenance) then

		{ If not prefixed with http:// or https:// add http:// }
		if upper(substring('(L) URL' of window IV_Item_Maintenance of form IV_Item_Maintenance, 1, 7)) <> upper("http://") and
		upper(substring('(L) URL' of window IV_Item_Maintenance of form IV_Item_Maintenance, 1, 8)) <> upper("https://") then
			'(L) URL' of window IV_Item_Maintenance of form IV_Item_Maintenance = 
					substring("http://" + '(L) URL' of window IV_Item_Maintenance of form IV_Item_Maintenance, 1, 100);
		else
			{ If prefixed with http:// or https://, then check it is lower case and update if needed }
			if substring('(L) URL' of window IV_Item_Maintenance of form IV_Item_Maintenance, 1, 5) <>
				lower(substring('(L) URL' of window IV_Item_Maintenance of form IV_Item_Maintenance, 1, 5)) then
				'(L) URL' of window IV_Item_Maintenance of form IV_Item_Maintenance = 
					lower(substring('(L) URL' of window IV_Item_Maintenance of form IV_Item_Maintenance, 1, 5)) +
					substring('(L) URL' of window IV_Item_Maintenance of form IV_Item_Maintenance, 6, 
						length('(L) URL' of window IV_Item_Maintenance of form IV_Item_Maintenance)-5);
			end if;
		end if;
		
		err_val = OLE_SetProperty("OUT_Condition", TRUE_STRING);
	end if;
end if;

ITEM URL BUTTON Trigger Script

local boolean err_val;
local string IN_OldValue;
local string IN_NewValue;

err_val = OLE_GetProperty("IN_OldValue", IN_OldValue);
err_val = OLE_GetProperty("IN_NewValue", IN_NewValue);

err_val = OLE_SetProperty("OUT_Condition", FALSE_STRING);

if isopen(form IV_Item_Maintenance) then
	if not empty('(L) URL' of window IV_Item_Maintenance of form IV_Item_Maintenance) then
		
		if IsWebClient() then
			Utility_LaunchUrl('(L) URL' of window IV_Item_Maintenance of form IV_Item_Maintenance);
		else
			run application "", '(L) URL' of window IV_Item_Maintenance of form IV_Item_Maintenance;
		end if;

		err_val = OLE_SetProperty("OUT_Condition", TRUE_STRING);
	end if;
end if;

Hope you find this series useful.

David

This article was originally posted on http://www.winthropdc.com/blog.

One thought on “#GPPT Beginner’s Guide to Adding Custom Fields – Using the data

Please post feedback or comments

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.