Simple calculation of an Order line total

I am trying to just multiply 

FormatDecimal(Input_OrderQuantity * Input_ProductPrice)

And come up with a total for the orderline but this doesn't work.

I am selecting a product from a separate Product database and trying to multiply price X quantity


Solution

Hello Alan,

Please find attached the updated OML. I have made changes only to your OrderLineDetails screen, since there are a lot of changes required to run all the screens properly.

It looks like you are very new to the OutSystems and not much familiar with OutSystems basics. I would request you to please go through with all the available study material first and then try to implement it gradually, so you can know how to use and implement the things in OS.

Let me know, if you need any other help. Have a great weekend!

Thanks & Kind Regards,

Sachin

CloneOfCO32Sachin.oml

I tried to run your version but got an upgrade error

Could you please try this OML? I have published this into lower version. 

CloneOfCO32Sachin.oml

Upgrade Error


Could not create foreign key constraint. This may have happened because there are 'ProductId' values of entity 'OrderLine' with no corresponding value in entity 'Product', or attribute 'ProductId' of entity 'OrderLine' is creating a circular dependency between entities. Check the Error Log for more information.

I am using below version. Could you please check your version?

Hi Alan,

As suggested in another note, please delete module and republish my OML to solve this issue. Once you publish the OML do your analysis and let us know, if you need any other help.

Thanks & Kind Regards,

Sachin

mvp_badge
MVP

Hi Alan PeslaK,

It seems that expression is multiplying input widgets directly?... You should be using the variables bound to the widgets (what you put in the Variable property of those input widgets).

Can you give us more context on what is you are trying to accomplish, not just that particular expression? Are you trying to assign a value to OrderLine.OLTotal before you write the OrderLine to the database?

Hi Alan PeslaK ,

As per my understanding, I think you are assigning to the Orderline.OLTotal value and this should be the value to accomplish Formatdecimal(Orderline.Orderquantity * Product.ProductPrice,".","")


mvp_badge
MVP

@Alan PeslaK and @Harika Ramadalai,

Regarding the use of FormatDecimal... it is used to convert a decimal into a Textual representation. In general that's done when we are displaying data on a screen, not when we store any information on the database.

Champion

@Harika, It seems that Alan is trying to achieve the same in Aggregate Itself using the Functional Attribute. It is not possible to use FormatDecimal() in Database. 


@Alan PeslaK 

We cannot use the FormatDecimal Function in the Database. You will need to make simple Multiply in the Aggregate and while showing value using the Expression, you can use FormatDecimal to control the Value Format. 


If you are trying to multiply this in Aggregate - Simple use the multiply there and while showing value to the customer use FormatDecimal 

  

In formatDecimal you will need to pass 4 parameters as @Harika explained. 

Please do remember you should have Price Attribute in Database as Decimal Datatype. 


If you are trying to multiply the input fields value - Then you will need to Multiply the Values not Fields. So, take the values you have assigned to Inputboxes. You can find the variable value as below screenshot.


And then add the FormatDecimal Operation on the Variables 


I hope these screenshots will help you to understand the workaround. 


Thanks

Thanks for the responses but I guess I wasn't clear. I just want to multiply Price X Quantity and store it in the order line total. In the screen shot below I am trying to select a product, pull a price of the product from the Product table and then multiply Price X Quantity which I enter in. I am getting the product selection but it is not pulling price and I have no idea how to make the calculation and then "write" it to the OL Total field. Sorry for the newbie question but this syntax is a bit confusing. I have also attached the .oml file

CloneOfCO32.oml

Solution

Hello Alan,

Please find attached the updated OML. I have made changes only to your OrderLineDetails screen, since there are a lot of changes required to run all the screens properly.

It looks like you are very new to the OutSystems and not much familiar with OutSystems basics. I would request you to please go through with all the available study material first and then try to implement it gradually, so you can know how to use and implement the things in OS.

Let me know, if you need any other help. Have a great weekend!

Thanks & Kind Regards,

Sachin

CloneOfCO32Sachin.oml

I tried to run your version but got an upgrade error

Could you please try this OML? I have published this into lower version. 

CloneOfCO32Sachin.oml

Upgrade Error


Could not create foreign key constraint. This may have happened because there are 'ProductId' values of entity 'OrderLine' with no corresponding value in entity 'Product', or attribute 'ProductId' of entity 'OrderLine' is creating a circular dependency between entities. Check the Error Log for more information.

I am using below version. Could you please check your version?

Hi Alan,

As suggested in another note, please delete module and republish my OML to solve this issue. Once you publish the OML do your analysis and let us know, if you need any other help.

Thanks & Kind Regards,

Sachin

Hello Alan,

I have modified the orderline detail screen and attaching the oml . Request you to go through outsystems basics to understand how to implement in OS. 


CloneOfCO32.oml

Good morning guys,

this problem publishing has nothing to do with Service Studio versions.

The error message says exactly what is going on : it can't create a foreign key from order line to product because some order line records would violate the foreign key.

So the reason is that Sachin has done more than he says in his reply, he has also changed the entity definition of order line.  

In Alans module :


In Sachins Module :

I think Sachin has removed ProductId2 and turned ProductId into a foreign key.  This means that a constraint now is to be put in place by the platform/database that every value of ProductId in OrderLine also exists in Product table.  As you  probably already have bad order lines in your test database, with maybe product id = 0, the platform can't do this, and so can't publish your changes.

So how to solve this ?  

What works will depend on what sequence things have been done in.  You can search the forum for all kinds of tips and tricks for this, things such as cutting and pasting entity definitions and so on.  

I think the simplest for a beginner like you Alan, is to remove all orderlines (using for example the data tab in your old module.  (won't work with Sachin's version, Service Studio won't allow it because data definition has changed)

Or else, maybe something like this

* rename ProductId back to ProductId2 in Sachin's module

* publish

* use the 'view or edit data' functionality of Service Studio to either delete all rows, or give all rows a valid value for attribute ProductId2

* rename back to ProductId

* publish

Or maybe it would be less hassle to just remove the existing module from your environment, use something like db cleaner on steroids to make sure everything is gone, and then open and publish the version of Sachin.

Good luck,

Dorine

Hi Dorine,

You are right. This is what I have analyzed too and as you had suggested the solution to this problem is to delete the module and publish the OML which I had shared. I have made so many corrections to his OML to made it workable for him. 

Thanks for your suggestion!

Thanks & Kind Regards,

Sachin


Thank you everyone. Yes I had to delete the module through the admin portal and then install. I see the calculation. Thanks so much.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.