Hello, 


So, I've this scenario where I've posts and I want to be able to use the same ''posts form screen'' to edit a record and also to add a new one but somehow, form already has values on it's inputs. I tried to use nullidentifier but it keeps showing the last table record when I navigate from a page to another. 

Hi Carolina,

Am I assuming correctly that you're referring to the CreateNew page? Your GetSummaryPostById Aggregate in the preparation doesn't have a filter, so it will always fetch the first record it finds. This is probably why you're always seeing data on the form even with a NullIdentifier() as input.

Yes! I was referring to ''CreateNew". 

Ok I made I filter but now i've the exact opposite problem as in, if i ''create'' inside the categories screen i want it to already have the values from previous page (category and subcategory). I added an input parameter id with those values but since im using the form's variable it doesn't work. Should i replace that input's variable ?

Can you share you new oml pls

In the preparation if id is nullidentifier() (is a creation) you should assign those to variables to GetSummaryPostById

Something like this.

that should fill the sub category and category with the values you send in the button create


EDIT: I noticed that you postId in your createNew screen is a entity structure. You should change that to a Post Identifier or change the name something that doesnt deceive other fellow programmers

Can you share an OML with your new changes, Carolina?

Yes, thanks!

That solved the issue with the inputs but now i get an internal error everytime I post but it still updated the DB. 

I debuged you application and found out what was the problem.


You should have debug the application before post the error.


When you do create a record in the navigation you are passing an id that is nullidentifier()

you should pass  the id resulted from the create action "CreatePost.Id"


Other thing i find out and where the aplication is returning exception is 

You really need to be carful where you use the outsystems getfunction since they will return exception if dont find anything. 

Since you are trying to call  GetPost(id that is returned from previous "create action" and that id is null because you use the wrong id) the aplication is retunign exception here.


fixing the navigation in the create action will fix this issue but i advise you not to use outsystems get functions if you are not sure this id will be null in some situation.


For example in your case you could do a getaggregate (max record 1) in preparation to get Post by that id and then use that aggregate to fill that 4 expressions.

Hi Carolina,

In the future, you can access ServiceCenter (your-environment.com/ServiceCenter) and check this tab:

it will provide you with more details regarding any errors in your application, and will help you to diagnose the problem with a stack trace.

Carlos Gonçalves wrote:

I debuged you application and found out what was the problem.


You should have debug the application before post the error.


When you do create a record in the navigation you are passing an id that is nullidentifier()

you should pass  the id resulted from the create action "CreatePost.Id"


Other thing i find out and where the aplication is returning exception is 

You really need to be carful where you use the outsystems getfunction since they will return exception if dont find anything. 

Since you are trying to call  GetPost(id that is returned from previous "create action" and that id is null because you use the wrong id) the aplication is retunign exception here.


fixing the navigation in the create action will fix this issue but i advise you not to use outsystems get functions if you are not sure this id will be null in some situation.


For example in your case you could do a getaggregate (max record 1) in preparation to get Post by that id and then use that aggregate to fill that 4 expressions.

I fixed what you described and it worked also I tried to use that ''createnew'' screen to make an edit screen to the ''myrequest'' posts, and I'm having no problem with the ID, keywords, category, subcategory  but the ''summary'' input isn't gettin any values. I don't know if it's because of the CK Editor API that I'm using or if it stills something im missing. 

Afonso Carvalho wrote:

Hi Carolina,

In the future, you can access ServiceCenter (your-environment.com/ServiceCenter) and check this tab:

it will provide you with more details regarding any errors in your application, and will help you to diagnose the problem with a stack trace.

Thanks Afonso! That's really helpful


Solution

Carolina Santos wrote:

I fixed what you described and it worked also I tried to use that ''createnew'' screen to make an edit screen to the ''myrequest'' posts, and I'm having no problem with the ID, keywords, category, subcategory  but the ''summary'' input isn't gettin any values. I don't know if it's because of the CK Editor API that I'm using or if it stills something im missing. 


I was analyzing that part of your code and you have some problems there i will try to explain them (i provide an  oml in the end some changes):


1st You have a structure input called postForm and that structure cannot be passed in a navigation action as an input. What that this mean? that when you click on your pencil in that edit screen you cannot tell the CreateNew Screen what id he should be editing.

I made some change to your code to be more like the standard Outystems apps (there is a lot of ways to do this)

What i changed was that input you had called postform. There is no need to have that, you only need the postId

Then fix some problems inside of the CrateNew Screen.


2nd your GettSummaryPostById In the preparation of the screen  CreateNew screen have a filter that will allways fill the form with nullvalues. You do not want that. You want the form empty when it is creating but when is edit you want the values of the Id.


3rd you edit pencil is not passing any id to the other screen so outsystems do not know what you want to edit.

4rd you have a create action on the save button and it need to be replaced with create and update else aplication will keep creating new records.


Last: Related to Ck Editor i was trying to find why was it not showing after i fixed all the other problems, and it start showing after i remove the style input and the 100000 limit you had there. I do not know why it has this behavior since i never worked with ck editor.


BR



Solution

Ok thanks! 

Before downloading your file I tried to understand the logic and made the changes and now everything is working 100%. What you suggested is way more intuitive and ''effortless'' when compared to what I was doing. Thanks! 

Still, there's something I wanted to ask for a while now, like, how can i filter a combo box? On the second combo box i want to display only the subcategories that have the same ID of the category selected previously. 

Thanks again 


Carolina Santos wrote:

Ok thanks! 

Before downloading your file I tried to understand the logic and made the changes and now everything is working 100%. What you suggested is way more intuitive and ''effortless'' when compared to what I was doing. Thanks! 

Still, there's something I wanted to ask for a while now, like, how can i filter a combo box? On the second combo box i want to display only the subcategories that have the same ID of the category selected previously. 

Thanks again 


to do that instead of using the source entity you need to create you own record list 

To do that, you need a query in the preparation that receive a caterogy id and then puck that query and place it on the combo box.

NOTE: when you select a value in category you need to refresh that query with the new id. 


Eg: every time you change the value o category you need to refresh subcategory (this is made with an onchange action on the category combo box), when you try to edit a existing post, you already have a category so the subcategory combo box need to filtered in the preparation even before you start choosing any value.


When you create a new one and you dont have any category selected, the subcategory combobox will be empty.


so to do this by steps i suggest:


1st create aggregate or advancequery in preparation with a filter base on category (i want all subcategories that have X category)

2nd change the subcategory combobox to receive that aggregate insted of source entity subcategory

3rd go to combo box and create a action on change to refresg the  query that is filling the subquery combobox.


after this 3 are done test to see if it is working.


After that you need to fix other things like what happen when i am editing ad when i am creating and when i select nothing in category combobox