Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

division of two fields using jolt spec

avatar
Rising Star

i'm trying to perform Importo= importo/Quantita  for each line item value.

 

but unable get the division even though i've used =divide function. Could you please help me

input:

{
"FatturaElettronicaBody": {
"DatiBeniServizi": {
"DettaglioLinee": [
{
"NumeroLinea": 1,
"Quantita": "3.0",
"PrezzoUnitario": "311.55000000",
"AliquotaIVA": "22.00",
"ScontoMaggiorazione": [
{
"Tipo": "SC",
"Percentuale": "28.00",
"Importo": "261.69"
}
],
"Descrizione": "B66450458 SACCA DA GOLF",
"PrezzoTotale": "672.96000000"
},
{
"NumeroLinea": 2,
"Quantita": "1.00000000",
"PrezzoUnitario": "311.55000000",
"AliquotaIVA": "22.00",
"ScontoMaggiorazione": [
{
"Tipo": "SC",
"Percentuale": "28.00",
"Importo": "87.23000000"
}
],
"Descrizione": "B66450458 SACCA DA GOLF",
"PrezzoTotale": "224.32000000"
},
{
"NumeroLinea": 3,
"Quantita": "1.00000000",
"PrezzoUnitario": "311.55000000",
"AliquotaIVA": "22.00",
"ScontoMaggiorazione": [
{
"Tipo": "SC",
"Percentuale": "28.00",
"Importo": "87.23000000"
}
],
"Descrizione": "B66450458 SACCA DA GOLF",
"PrezzoTotale": "224.32000000"
},
{
"NumeroLinea": 4,
"Quantita": "3.00000000",
"PrezzoUnitario": "2150.00000000",
"AliquotaIVA": "22.00",
"ScontoMaggiorazione": [
{
"Tipo": "SC",
"Percentuale": "16.00",
"Importo": "1032.00000000"
}
],
"Descrizione": "A205330410780 INGRANAGGI E DIFFER. ANT.",
"PrezzoTotale": "5418.00000000"
},
{
"NumeroLinea": 5,
"Quantita": "7.00000000",
"PrezzoUnitario": "202.96000000",
"AliquotaIVA": "22.00",
"ScontoMaggiorazione": [
{
"Tipo": "SC",
"Percentuale": "19.00",
"Importo": "269.92000000"
}
],
"Descrizione": "A6510108918 COPERCHIO TESTATA CIL.",
"PrezzoTotale": "1150.80000000"
}
]
}
}
}

 

 

Jolt Spec:

[{
"operation": "modify-overwrite-beta",
"spec": {
"FatturaElettronicaBody": {
"DatiGenerali": {
"DatiBeniServizi": {
"DettaglioLinee": {
"*": {
"ScontoMaggiorazione": {
"*": {
"Importo": "=divide(@(1,Importo),@(1,Quantita))"
}
}
}
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"FatturaElettronicaBody": {
"DatiBeniServizi": {
"DettaglioLinee": {
"*": {
"NumeroLinea": "FatturaElettronicaBody.DatiBeniServizi.DettaglioLinee[&1].NumeroLinea",
"Descrizione": "FatturaElettronicaBody.DatiBeniServizi.DettaglioLinee[&1].Descrizione",
"Quantita": "FatturaElettronicaBody.DatiBeniServizi.DettaglioLinee[&1].Quantita",
"PrezzoUnitario": "FatturaElettronicaBody.DatiBeniServizi.DettaglioLinee[&1].PrezzoUnitario",
"ScontoMaggiorazione": {
"*": {
"Importo": "FatturaElettronicaBody.DatiBeniServizi.DettaglioLinee[&3].ScontoMaggiorazione[&3].Importo"
}
}
}
}
}
}
}
}]

2 ACCEPTED SOLUTIONS

avatar

Hi,

Please see the modified spec below. The comments indicate what I had to do to make your modify-overwrite-beta spec works based on the input json. I hope it works.

 

[{
  "operation": "modify-overwrite-beta",
  "spec": {
    "FatturaElettronicaBody": {
      // The DatiGenerali level is not found in the input JSON
      // "DatiGenerali": {
      "DatiBeniServizi": {
        "DettaglioLinee": {
          "*": {
            //level3 
            "ScontoMaggiorazione": {
              // level2
              "*": {
                // Quantita is located level 3 and not level 1
                "Importo": "=divide(@(1,Importo),@(3,Quantita))"
              }
            }
          }
        }
      }
      //}
    }
  }
}]

 

 

View solution in original post

avatar

I think you had it right but you need to convert the division value into string before applying split on it. Here are the steps:

 

 

 "decImporto": "=divide(@(1,Importo),@(3,Quantita))",
 "strImporto": "=toString(@(1,decImporto))",
 "array_importo": "=split('[.]',@(1,strImporto))",
 "pad_importo": "=rightPad(@(1,array_importo[1]), 8, '0')",
 "Importo": "=concat(@(1,array_importo[0]),'.',@(1,pad_importo))"
      

 

View solution in original post

3 REPLIES 3

avatar

Hi,

Please see the modified spec below. The comments indicate what I had to do to make your modify-overwrite-beta spec works based on the input json. I hope it works.

 

[{
  "operation": "modify-overwrite-beta",
  "spec": {
    "FatturaElettronicaBody": {
      // The DatiGenerali level is not found in the input JSON
      // "DatiGenerali": {
      "DatiBeniServizi": {
        "DettaglioLinee": {
          "*": {
            //level3 
            "ScontoMaggiorazione": {
              // level2
              "*": {
                // Quantita is located level 3 and not level 1
                "Importo": "=divide(@(1,Importo),@(3,Quantita))"
              }
            }
          }
        }
      }
      //}
    }
  }
}]

 

 

avatar
Rising Star

Thanks @SAMSAL  for the quick help. division got worked

but after this division the value coming with 2 decimal values , where as i needed 8 decimal points after the dot. so far that i've used below logic in the same spec. but its giving empty value.

 

"ScontoMaggiorazione": {
"*": {
"first_Importo": "=divide(@(1,Importo),@(3,Quantita))",
"array_importo": "=split('.',@(1,first_Importo))",
"pad_importo": "=rightPad(@(1,array_importo[1]), 8, '0')",
"Importo": "=concat(@(1,array_importo[0]),'.',@(1,pad_importo))"
}

 

 

any idea on this too?

avatar

I think you had it right but you need to convert the division value into string before applying split on it. Here are the steps:

 

 

 "decImporto": "=divide(@(1,Importo),@(3,Quantita))",
 "strImporto": "=toString(@(1,decImporto))",
 "array_importo": "=split('[.]',@(1,strImporto))",
 "pad_importo": "=rightPad(@(1,array_importo[1]), 8, '0')",
 "Importo": "=concat(@(1,array_importo[0]),'.',@(1,pad_importo))"