This topic is locked
[SOLVED]

 10.5 Dialog API

12/24/2020 1:54:46 PM
PHPRunner General questions
R
RBrogen author

Hi Everyone,
I'm trying to use the new 10.5 version of Dialog API to pass database values form Server side to Client After. I have a table that contains an id column and a description column. I want to provide the user with a drop down of the description field and then based on their selection, use the associated id for another operation. Does anyone have a reference to someone who has an example of using the new 10.5 Dialog API with a data lookup? Any guidance would be very appreciated.
Thanks and Happy Holidays!

Randy

Myr0n 12/25/2020

In the documentation dialog api Example 2. Dialog with a lookup wizard it's straight forward
in server side you need to populate the array that you go to show to your clients

$rs = DB::Query("SELECT * FROM CodesTypes");

$ArrayOfSelectedRecords = array();

while( $data = $rs->fetchAssoc() )

{

$ArrayOfSelectedRecords[] = array($data['ID'], $data['Description']);

}

$result['ArrayOfSelectedRecords'] = $ArrayOfSelectedRecords;


and in the After server side you need to copy the code in the documentation and only change the Options for your populated array.

ArrayOfSelectedRecords = result['ArrayOfSelectedRecords'];

return Runner.Dialog( {

title: 'Preferences',

fields: [{

code: 'color',

type: 'lookup',

value: 2,

options: ArrayOfSelectedRecords

}],

ok: 'Save',

cancel: 'Cancel',

beforeOK: function( popup, controls ) {

swal('Success', 'Selected color: ' + controls[0].val(), 'success');

}

});


Don't forget to change the default value, messages etc...

R
RBrogen author 12/26/2020

THANK YOU SOOOOOOOO MUCH!!! THIS WORKED PERFECTLY! Happy Holidays you sure made mine!



In the documentation dialog api Example 2. Dialog with a lookup wizard it's straight forward
in server side you need to populate the array that you go to show to your clients

$rs = DB::Query("SELECT * FROM CodesTypes");

$ArrayOfSelectedRecords = array();

while( $data = $rs->fetchAssoc() )

{

$ArrayOfSelectedRecords[] = array($data['ID'], $data['Description']);

}

$result['ArrayOfSelectedRecords'] = $ArrayOfSelectedRecords;


and in the After server side you need to copy the code in the documentation and only change the Options for your populated array.

ArrayOfSelectedRecords = result['ArrayOfSelectedRecords'];

return Runner.Dialog( {

title: 'Preferences',

fields: [{

code: 'color',

type: 'lookup',

value: 2,

options: ArrayOfSelectedRecords

}],

ok: 'Save',

cancel: 'Cancel',

beforeOK: function( popup, controls ) {

swal('Success', 'Selected color: ' + controls[0].val(), 'success');

}

});


Don't forget to change the default value, messages etc...

R
RBrogen author 12/26/2020

Hi Myr0n,
I have the Server Side and Client After prompts relabeled and functioning. In my manual selection code, I have the code that performs the additional tasks needed but when I am running into an issue because it doesn't execute after the prompt and it errors out when I replace the beforeOK section. Any guidance or suggestion would be greatly appreciated. I'm continuing to try different formats and locations to get it to work.
Basically I want to replace:



beforeOK: function( popup, controls ) {

swal('Success', 'Selected color: ' + controls[0].val(), 'success');

}


With this:



window.open('cron3.php?a=sendnow&taskid='+controls[0].val()+'&commNotes='+result["comm_Notes"]+'&client_ID='+result["clientID"])




In the documentation dialog api Example 2. Dialog with a lookup wizard it's straight forward
in server side you need to populate the array that you go to show to your clients

$rs = DB::Query("SELECT * FROM CodesTypes");

$ArrayOfSelectedRecords = array();

while( $data = $rs->fetchAssoc() )

{

$ArrayOfSelectedRecords[] = array($data['ID'], $data['Description']);

}

$result['ArrayOfSelectedRecords'] = $ArrayOfSelectedRecords;


and in the After server side you need to copy the code in the documentation and only change the Options for your populated array.

ArrayOfSelectedRecords = result['ArrayOfSelectedRecords'];

return Runner.Dialog( {

title: 'Preferences',

fields: [{

code: 'color',

type: 'lookup',

value: 2,

options: ArrayOfSelectedRecords

}],

ok: 'Save',

cancel: 'Cancel',

beforeOK: function( popup, controls ) {

swal('Success', 'Selected color: ' + controls[0].val(), 'success');

}

});


Don't forget to change the default value, messages etc...

Myr0n 12/26/2020

You need to replace this

beforeOK: function( popup, controls ) {

swal('Success', 'Selected color: ' + controls[0].val(), 'success');

}



for this

beforeOK: function( popup, controls ) {

window.open('cron3.php?a=sendnow&taskid='+controls[0].val()+'&commNotes='+result["comm_Notes"]+'&client_ID='+result["clientID"]);

}


practically it's just replace the swal code.

you where close.

J
John 12/27/2020

Not 100% certain on your goal but you need to use the setProxyValue funtion in order to make this function.

Take the function defined earlier: and not use it in the service side but use it as a Before Display event.

$rs = DB::Query("SELECT * FROM CodesTypes");

$ArrayOfSelectedRecords = array();

while( $data = $rs->fetchAssoc() )

{

$ArrayOfSelectedRecords[] = array($data['ID'], $data['Description']);

}
Move the client after code to the before client side.
Once the value is selected in the dialog box you can use the result["clientID"] for example you can use it cause some PHP side server event.. for example right the selected choice to a table..
John

Myr0n 12/27/2020



> Not 100% certain on your goal but you need to use the setProxyValue funtion in order to make this function.

Take the function defined earlier: and not use it in the service side but use it as a Before Display event.

$rs = DB::Query("SELECT * FROM CodesTypes");

$ArrayOfSelectedRecords = array();

while( $data = $rs->fetchAssoc() )

{

$ArrayOfSelectedRecords[] = array($data['ID'], $data['Description']);

}
Move the client after code to the before client side.
Once the value is selected in the dialog box you can use the result["clientID"] for example you can use it cause some PHP side server event.. for example right the selected choice to a table..
John


According to thecustom buttons documentationif you move the code to the before client you will not be able to get the information from the server side

R
RBrogen author 12/27/2020

Hey JSD, Myr0n is correct. I thought I completed a post yesterday of my working version but it didn't get posted successfully so I will post it below. I had to approach this in a way that I could retrieve the server information first before prompting the user because the data that I had retrieved from the server is what I displayed in a prompt to the user. Thank you both for taking the time to respond. I wanted to post the working version so that someone else may find it useful. I don't do this full time so I'm usually relearning syntax and features. Thanks again and Happy and Safe Holidays!
SERVER


//retrieve records from sql table

$rs = DB::Query("SELECT * FROM mmtasks");
//create an array to store the results of the query

$ArrayOfSelectedRecords = array();

while( $data = $rs->fetchAssoc() )

{

$ArrayOfSelectedRecords[] = array($data['id'], $data['description']);

}
//pass the array to the client after

$result['ArrayOfSelectedRecords'] = $ArrayOfSelectedRecords;
//for each record selected, update their correspondence record to show transaction

while($Ordersdata = $button->getNextSelectedRecord()) {

$correspondenceUpdate["client_FK"] = $Ordersdata["client_FK"];

if ($i==0) {



$result['clientID'] = $Ordersdata["client_FK"];

db::Insert("CORRESPONDENCE", $correspondenceUpdate);

$i++;



} else {



$result['clientID'] = $result['clientID'] . " OR client_ID = " .$Ordersdata["client_FK"];

db::Insert("CORRESPONDENCE", $correspondenceUpdate);

$i++;



}

}



CLIENT AFTER


//retrieve the array of results from the server side

ArrayOfSelectedRecords = result['ArrayOfSelectedRecords'];
//prompt the user with the list of email templates to choose from and based on their selection, send the result to be processed for emailing template

return Runner.Dialog( {

title: 'Select Email Template',

fields: [{

code: 'color',

type: 'lookup',

value: 2,

options: ArrayOfSelectedRecords

}],

ok: 'Send',

cancel: 'Cancel',

beforeOK: function(test, controls) {
window.open('cron3.php?a=sendnow&taskid='+ controls[0].val() + '&commNotes='+result["comm_Notes"] + '&client_ID=' + result["clientID"]);



}



});




According to thecustom buttons documentationif you move the code to the before client you will not be able to get the information from the server side

J
John 1/4/2021



Hey JSD, Myr0n is correct. I thought I completed a post yesterday of my working version but it didn't get posted successfully so I will post it below. I had to approach this in a way that I could retrieve the server information first before prompting the user because the data that I had retrieved from the server is what I displayed in a prompt to the user. Thank you both for taking the time to respond. I wanted to post the working version so that someone else may find it useful. I don't do this full time so I'm usually relearning syntax and features. Thanks again and Happy and Safe Holidays!
SERVER


//retrieve records from sql table

$rs = DB::Query("SELECT * FROM mmtasks");
//create an array to store the results of the query

$ArrayOfSelectedRecords = array();

while( $data = $rs->fetchAssoc() )

{

$ArrayOfSelectedRecords[] = array($data['id'], $data['description']);

}
//pass the array to the client after

$result['ArrayOfSelectedRecords'] = $ArrayOfSelectedRecords;
//for each record selected, update their correspondence record to show transaction

while($Ordersdata = $button->getNextSelectedRecord()) {

$correspondenceUpdate["client_FK"] = $Ordersdata["client_FK"];

if ($i==0) {
$result['clientID'] = $Ordersdata["client_FK"];

db::Insert("CORRESPONDENCE", $correspondenceUpdate);

$i++;
} else {
$result['clientID'] = $result['clientID'] . " OR client_ID = " .$Ordersdata["client_FK"];

db::Insert("CORRESPONDENCE", $correspondenceUpdate);

$i++;
}

}


CLIENT AFTER


//retrieve the array of results from the server side

ArrayOfSelectedRecords = result['ArrayOfSelectedRecords'];
//prompt the user with the list of email templates to choose from and based on their selection, send the result to be processed for emailing template

return Runner.Dialog( {

title: 'Select Email Template',

fields: [{

code: 'color',

type: 'lookup',

value: 2,

options: ArrayOfSelectedRecords

}],

ok: 'Send',

cancel: 'Cancel',

beforeOK: function(test, controls) {
window.open('cron3.php?a=sendnow&taskid='+ controls[0].val() + '&commNotes='+result["comm_Notes"] + '&client_ID=' + result["clientID"]);
}
});