Doubt about query depending on dropbox

Doubt about query depending on dropbox

  

Hi everyone,

I have a question that problably it's pretty easy to solve.

I'm creating an aplication that when a user is adding a new file the number of this file has to be the last one plus one. The problem is that this field (file_number) will be filled depending on the the value i've choosed in a dropbox.
I'll try to give an example. Let's say i have this table, with the followinf records:

ID File_number Company Name
1 1 A
2 2 A
3 4 B
4 7 C
5 8 B
6 10 B
7 11 C
8 21 A
9 22 B
10 23 B

When i'm adding a new file, the first field i have to choose is the Company Name that can be the following values: A, B or C.

After i'm done doing this choice, the field below that is the "File Number" should automatically be filled with the last value of corresponding Company, plus one.

Let's say i choosed company A, the "Filed Number" should have the value "22".

Can anyone help me doing this?

Thanks.

Can anyone help me, please?

Hi Nuno,

There are several ways to implement what you want, and probably there are people with more experience in OutSystems that can help you more.

I would do it like this.

1) On the DropBox "Company Name" On Change Property include as destination a new Screen Action (name it "RefreshFileNumber" for instance).
2) On the Screen Action "RefreshFileNumber" include a new Query, tal will return only one line, and select in it the File_Number, order descending, and filter by the value of the DropBox "Company Name"
3) Use an Assign to populate the new field "File Number" with the result of the Query + 1
4) Use a "Ajax Refresh" to refresh the screen corresponding to the field "File Number"
And your done.

Hope you can follow the instructions. If you can't, just send an example eSpace and I'll try to check it.

Best of luck,

Nuno Antunes



Hi Nuno,

Let me start my thanking you for the help.

I'll try and do that, and if i have any doubt i will contact you, ok?

Thanks again.
Hi Nuno,

I'm having a problem in the second step.

2) On the Screen Action "RefreshFileNumber" include a new Query, tal will return only one line, and select in it the File_Number, order descending, and filter by the value of the DropBox "Company Name"


The query that i make has to have a parameter, so that in my condition i have something like table.company_name = parameter.

The parameter should have the value of the dropbox of the company name. How do i assing the value of the dropbox to the parameter?

Thanks
Hi Nuno,

1) Create the Screen Action with an input parameter of type "CompanyName Identifier " where CompanyName is the name of the entity where you keep the companies.
2) On the "On Change" property of the dropbox pass the Id of the company name that you want to filter by.

If you don't have an Entity for CompanyName you can use an Input Parameter of type "Text".
What is important is that you use the same data type you have on table.company_name.

Use the same approach as above.

Good luck,

Nuno Antunes




Hi Nuno,

I've added the input parameter. But has you see by the printscreen, he asks me for the type of "CompanyName".
This should be the id of the table where i have my company, right?

But when i choose it, it gives me an error :(




Now i have two questions:

1)  On the "On Change" property of the dropbox pass the Id of the company name that you want to filter by. How do i do that?

2) Is the step 3 and 4 all in the same query?

Thanks again.


Hi Nuno Ferreira.

Nuno Antunes indeed has been a great help explaining in detail what you're trying to do - thank you very much for it!

However, by the look of your last question regarding the OnChange property, a question has come up to me... It might be the case that you're not very familiar with the Ajax capabilities of the Agile Platform (and, if that's the case, I recommend you watching this short video, and reading the PDFs on Ajax, since it'll get you up to speed in no time), or another possibility is that you are working on an older version of the Agile Platform.

What version are you working on? The OnChange property should be in the drop-down list properties panel. If you don't have it there, it means you're using an older version of the Platform.

Let us know if this helps.

Regards,

Paulo Tavares

Hi Paulo,

Yes, Nuno is really helping me out.

I'm using the free version of the Agile Platform. The version is the 5.0.2.8 .

Is the "OnChange" solved?



The problem is that i still have a problem with the type of the input parameter "CompanyName".

What is the option that i should choose?

I will take a look at the videos.

Thanks.
Hi Nuno

The OnChange property is present in all 5.0 versions, so you should have it there. It is a property of the combo-box widget, if you're using it.

In terms of the error you're facing - using the link widget - what he's complaining is that the input parameter CompanyName should be filled - probably with a text parameter, and not with the entity's Id attribute. Unless you can change the input parameter to the entity Id type, instead of text. That could make more sense, depending on the logic you're trying to apply.

I'm sure that the videos will help you work your way through this, but in terms of the data types, that is down to the data model architecture and application design - a topic we had already discussed when you were designing the relationships between the entities.

Regards,

Paulo Tavares
Hi Paulo,

Ok, let's see if we can clear some of my doubts.

On my screen action i've created an input parameter. The Data Type was TabEmpresas Identifier, so i thinl i won't be having any problem there.

Now i have two problems.

1) As you can see from the printscreen above i have a link to the "add_teste" page. This page has the "CompanyName" input paramater. 

On the right side, on the bottom, there's a field that i have to fill. I'ts right above the destination (CompanyName).

I've clicked on the expression editor wich took me to the window in the midle, but know i don't know what i have to fill. Can you explain me what i have to do?



2) Nuno Antunes saids previoulsy this: "2) On the "On Change" property of the dropbox pass the Id of the company name that you want to filter by."

Looking at the picture above, where do i do this? Is it the field above the "Destination" ? If i choose "CompanyName" for the field "CompanyName2" it creates an other input parameter called "CompanyName2".

 

Nuno, if you can i would also really appreciate your help in this, since you were the mentor of this idea.

Thanks to you all.

Nuno

PS- the first problem i can solve it, if i declare "Non Mandatory" the input parameter, wich i think i can do. Right?

I'm almost there.... but i'm missing some pointers....
Hi Nuno,

Thank you for the kind words.

I understand what you want to do clearly, the problem to explain it to you is that it depends on the internal work of your application.

If you could provide an eSpace with the entities in question and the Screen flow I could try to correct it. Anyway, I'm already using 5.1, so probably you wouldn't be able to open it.

Let's try to clear the main questions you have.

1) You should keep the parameter mandatory. If you don't, you will resolve the error, but you will not be able to use the query to get the result you want.

2) You can pass as a parameter either the Company Name or the Company Id, but you must chose one, and should be the one you will be querying. It depends on your design of the entities.

3) On the Expression Editor of the On Change property, you should send either the Company Name or the Company Id you want to query. This will be available on the ComboBox you have just chosen. If your combo box is bounded to a variable to hold the result, you should use that variable. Try to see want you have on the "Variable" property of the Combo Box.

Best of luck to you,

Nuno Antunes



Hi Nuno,

I really apreciatte your help.

I've tried everything i've know (wich is not much) and i can't make it to work.

1) You should keep the parameter mandatory. If you don't, you will resolve the error, but you will not be able to use the query to get the result you want. - after i made this the all thing didn't work.

2) You can pass as a parameter either the Company Name or the Company Id, but you must chose one, and should be the one you will be querying. It depends on your design of the entities. - I want to pass the Company ID.

3) On the Expression Editor of the On Change property, you should send either the Company Name or the Company Id you want to query. This will be available on the ComboBox you have just chosen. If your combo box is bounded to a variable to hold the result, you should use that variable. Try to see want you have on the "Variable" property of the Combo Box. - I want tho send the Company ID

I'm just a few minutes away from losing my mind, so i think i'll on that offer of sending you my espace.

I'm attached the espace.

Thanks. Again


Hi Nuno,

1) On the Destination parameter of the On Change of the Combo Box, put the following text "EditRecord1.Record.TabRegTrad.CodEmpresa". This is to send the Company Id of the company you have selected on the combo box.

2) On the query "Get_Accoes", you should set the "Max. Records" property to the value 1.

3) On the query "Get_Accoes", you should set a Order By TabRegTrad.NumOrdReg, Descending, to able you to get the last number of register of that company.

4) On the assign you should set the following variable as variable1 "
EditRecord1.Record.TabRegTrad.NumOrdReg", and should set Value1 to "get_accoes.List.Current.TabRegTrad.NumOrdReg+1". This will set your screen input field to the value of the last register plus one.

5) I've noticed that you are using the Ajax_Refresh only on the field "TabRegTrad_NumOrdReg". I don't know if it works like that, sorry but I'm also starting with OutSystems. In my experience I normally would refresh the "EditRecord1". But anyway, if it works with only the field it should be better for performance.

Follow the above and tell me if it works !

Good luck,

Nuno Antunes


Hi Nuno,

Again, thanks for all the help.

Some of the steps i already had done it, but didn't know if it was rigth.

1) On the Destination parameter of the On Change of the Combo Box, put the following text "EditRecord1.Record.TabRegTrad.CodEmpresa". This is to send the Company Id of the company you have selected on the combo box. - Already had done this



3) On the query "Get_Accoes", you should set a Order By TabRegTrad.NumOrdReg, Descending, to able you to get the last number of register of that company. - Already had done this.

4) On the assign you should set the following variable as variable1 "
EditRecord1.Record.TabRegTrad.NumOrdReg", and should set Value1 to "get_accoes.List.Current.TabRegTrad.NumOrdReg+1". This will set your screen input field to the value of the last register plus one. - Also i already had done this

5) I've noticed that you are using the Ajax_Refresh only on the field "TabRegTrad_NumOrdReg". I don't know if it works like that, sorry but I'm also starting with OutSystems. In my experience I normally would refresh the "EditRecord1". But anyway, if it works with only the field it should be better for performance. - Didn't know this

But still i have a problem, wich was one of the first ones.

I still don't know what to fill in that field.



I have a question:

is my query correct?

I added a input parameter called "ln1" wich i defined as TabEmpresas Identifier.

and in my condition i have something like TabRegTrad.CodEmpresa=ln1

Is this correct?

Hi Nuno,

This way is easier, I can always see what you mean by looking at the eSpace you provided.

1) In this case, you should delete the "CompanyName"  parameter from the "add_teste" web screen. I don't know why it's there in the first place.

2) You need to replace in the query "get_accoes" the In1 parameter should be "CompanyName2". (I would also change the name of "CompanyName2" to something like "CompanyId", because really what you are passing is the Id and not the name, so the variable name should indicate that.)

And I think your done. Please let me know how it goes.

Cheers,

Nuno Antunes

Hi Nuno,

I've followed every step, but it's not working.

In attachement is my espace so you can see if i'm doing anything wrong.

I mean, it's kind of working.

I have no errors, but when i run and change the value on the dropbox the value on field Num Ordem de Registo doesn't change.

Nuno,

I'm trying here, but you know that when you send the oml file, you don't send the data, so I really don't have any records to try with :(


But the code seems to be correct, right?

4) On the assign you should set the following variable as variable1 "EditRecord1.Record.TabRegTrad.NumOrdReg", and should set Value1 to "get_accoes.List.Current.TabRegTrad.NumOrdReg+1". This will set your screen input field to the value of the last register plus one.

Instead of having "get_accoes.List.Current.TabRegTrad.NumOrdReg+1" i've a value (10) but still it doesn't show the value after the refresh :(
Nuno,

Please double check your assign.

You should have Variable1="EditRecord1.Record.TabRegTrad.NumOrdReg", and should set Value1="get_accoes.List.Current.TabRegTrad.NumOrdReg+1" or =10 if your prefer for testings.
But the OML you have sent me is the other way arround. You have Variable1="Get_accoes...." and Value1="EditRecord....". Please correct it and try again.





Hi Nuno,

Good news!

It's working!!! I don't know how to thank you. I was getting crazy with this problem.

Thank you so much. Now i can rest this weekend.

Thanks for all your help.