Normal Topic My Awesome Process Button Has A Small Bug (Read 834 times)
BWETTLAUFER
Full Member
***
Offline



Posts: 216
Location: Cambridge, Ontario
Joined: Apr 9th, 2010
My Awesome Process Button Has A Small Bug
Sep 13th, 2016 at 8:10pm
Print Post Print Post  
Hey folks,

My cool new Process Button is great!  I can use it to allow limited Mass Updates, Exports, and Reports, all without use of the Command Tree sidebar ... however ...

Below is my code for the Mass Update button on element entry ... when I use it to run a mass update that calls a report, for example, it executes the report beautifully ... and then flips through 8000 records pulled up for the report (which isn't always fast), because it's a mass update. 

For reports, exports, and quick reports, how can I prevent 'record flipping'?

Code
Select All
#include "sbasic_include.sbas"

var vSpec1 as string
var vSpec2 as string
var vSpec3 as string
var vSpec4 as string
var vStaff as string
var vGoAhead as string

PopupSelectPosition(4, @Xpos(MassUpdate), @Ypos(MassUpdate))

vSpec1 = @SpecCommand(6,5,"")

if @group <> "Management"
{
	vStaff = @xlookup(@FN, @userid, "Staff Screen!StaffRef", "StaffMU")
	vSpec2 = @containsstringarray(vSpec1,vStaff,0)
	vSpec2 = @sortstringarray(vSpec2,0)
	vSpec3 = @Popupchoicelist(vSpec2,"CHOOSE AN UPDATE")
}
Else
{
	vSpec2 = vSpec1
	vSpec2 = @sortstringarray(vSpec2,0)
	vSpec3 = @Popupchoicelist(vSpec2,"CHOOSE AN UPDATE")
}

if vSpec3 <>""
{
	vGoAHead = @PromptForUserInput("Are you sure you want to run " + vSpec3 +"?  Type YES to Continue","")
	if vGoAhead = "YES"
	{
		vSpec4 = @SpecCommand(SPEC_OPERATION_LOAD, SPEC_TYPE_MASS_UPDATE, vSpec3)
		vSpec4 = @SpecCommand(SPEC_OPERATION_RUN, SPEC_TYPE_MASS_UPDATE, vSpec3)
	}
	Else @MsgBox("MASS UPDATE CANCELLED","TRY AGAIN","")
}
 

  
Back to top
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: My Awesome Process Button Has A Small Bug
Reply #1 - Sep 14th, 2016 at 2:27am
Print Post Print Post  
Depending on what your mass update code is doing, you might be able to use the @XResultSetRunProgram command, which runs the mass update code "engine-side".

In my tests, a mass update engine-side via @XResultSetRunProgram runs more than 50 times faster than a regular Mass Update.
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
BWETTLAUFER
Full Member
***
Offline



Posts: 216
Location: Cambridge, Ontario
Joined: Apr 9th, 2010
Re: My Awesome Process Button Has A Small Bug
Reply #2 - Sep 20th, 2016 at 4:54pm
Print Post Print Post  
Hi Carl,

I went to go play with this in my designer file, and I don't see any documentation for @XResultSetRunProgram in the programming guide.  What are the parameters/format requirements for using this command?
  
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: My Awesome Process Button Has A Small Bug
Reply #3 - Sep 20th, 2016 at 5:07pm
Print Post Print Post  
From the documentation available in the programming editor (right-click menu, select "List Browser", starting typing the name of the command you are interested in.):

@XResultSetRunProgram(rs as int, global_program as string, program as string, test_only as int) as string

This command runs an SBasic program, specified as a string argument, on every record in a result set. It returns as a string any content written using Write or WriteLn.

The programming is sent to the engine to be executed. Because it runs on the engine, the programming must use field names instead of element names. No commands that reference the user interface, forms, or reports are legal in the supplied program. For security, the File I/O commands, Shell commands and Process commands are disabled by default. These can be optionally allowed using the SERVER CODE FILE I/O and SERVER CODE SHELL INI file entries, but you should consider carefully before doing so.

NOTE: Because this method of working with a group of records works directly on the engine, it is much faster than a normal mass update, but it also is able to provide less feedback. You should always test this command using a backup of your data to make sure that is doing what you intend.

Arguments:
rs - Handle to a result set

global_program - Programming that you would type into the GLOBAL CODE area

program - Programming to run on each record in the result set

test_only - Flag indicating whether to actually run the program. 0 runs the program. 1 tests whether the program compiles without running it.

As the program compiles on the engine, the syntax error interface available in the Programming Editor is not available, however, @Error will be set if the program fails to compile. To test your program, set test_only to 1 and check @Error.

For easier assembly of the program to be run into a string, you can write it using single quotes or another unlikely "placeholder" character where double quotes would normally appear. You can then use @Replace to replace the placeholder with double quotes. The example below sets Company to "No company name provided" on any record where Company is blank.


#include "sbasic_include.sbas"

var key as int
var pgm as string
var str as string

        // Use single quotes to for strings internal to the program string
        pgm = "XCompany = 'No company name provided'"

        // and replace them with double quotes
        pgm  = @Replace(pgm, "'", @Chr(34))

        key = @XResultSetSearch(@FN, "Customers", SEARCH_MODE_AND, SEARCH_SYNTAX_QA, "!Company==")
        if(key > -1)
        {
                str = @XResultSetRunProgram(key, "", pgm, 0)
                If @Error
                {
                        WriteLn("Program failed to compile.")
                }
                XResultSetClose(key)
        }
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged