> ## Documentation Index
> Fetch the complete documentation index at: https://docs.superoffice.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Update quote

> How to update or delete a quote with CRMScript

Updates to a quote mostly target the [alternatives][4] and [quote lines][3]. You will, however, see some changes to the quote properties when dealing with [quote documents][5] and [placing orders][6].

When updating quotes, you'll always be working on the latest version.

## Update version

This example extends the expiration date by 1 week:

```crmscript theme={null}
NSQuoteAgent qa;
NSQuoteVersion version = qa.GetQuoteVersion(3);

version.SetExpirationDate(version.GetExpirationDate().addDays(7));

version = qa.SaveQuoteVersion(version);

printLine("New expiration date: " + version.GetExpirationDate().toString());
```

<Tip>
  Remember to call `SaveQuoteVersion()` whenever you update a version!
</Tip>

## NSQuoteVersion CreateAndSaveQuoteVersion(Integer quoteVersionId)

Creates a new version based on another version of the same quote. This is your only option when you want to edit a sent quote.

```crmscript theme={null}
NSQuoteAgent qa;
NSQuoteVersion version = qa.CreateAndSaveQuoteVersion(2);
```

## NSQuoteLine RecalculateQuoteLine(NSQuoteLine quoteLine, String\[] changedFields)

Many numbers in a quote line depend on each other, and changing 1 will affect others. The quote connector recalculates and updates those values so that you don't have to worry about miscalculating. All you have to do is call `RecalculateQuoteLine()` to signal which fields have changed.

For example, if you change the quantity, the total price and VAT amount should change too.

**When to recalculate:**

* Quantity
* DiscountAmount
* DiscountPercent
* ListPrice

When any of these fields are changed, you must recalculate. The format is `TableName.FieldName`.

```crmscript! theme={null}
NSQuoteAgent qa;
NSQuoteLine line = qa.GetQuoteLine(2);

printLine("Total price before: line.GetTotalPrice().toString(2));

line.SetQuantity(line.GetQuantity()*2);

String[] changedFields;
changedFields.pushBack("QuoteLine.Quantity");

line = qa.RecalculateQuoteLine(line, changedFields);
line = qa.SaveQuoteLine(line);

printLine("Total price after: line.GetTotalPrice().toString(2));
```

This example doubles the existing quantity.

## Void MoveQuoteLine(Integer quoteLineId, Bool direction)

Re-sorts the quote lines of an alternative by moving a specific line up or down.

**Direction:**

* true = move line up
* false = move line down

```crmscript theme={null}
NSQuoteAgent qa;
qa.MoveQuoteLine(2,true);
```

## Delete quote line

```crmscript theme={null}
Integer quoteLineId = 7;
NSQuoteAgent qa;
qa.DeleteQuoteLine(quoteLineId);
```

## Delete quote alternative

```crmscript theme={null}
Integer quoteAlternativeId = 13;
NSQuoteAgent qa;
qa.DeleteQuoteAlternative(quoteAlternativeId);
```

## Delete quote

<Warning>
  Always check before deleting. There might be legal and/or financial reasons to keep quote info in the system.
</Warning>

```crmscript theme={null}
Integer quoteId = 13;
NSQuoteAgent qa;
qa.DeleteQuote(quoteId);
```

## References

### Frequently used QuoteVersion fields

| Field                    | Description                                                            |
| :----------------------- | :--------------------------------------------------------------------- |
| quoteversion\_id         | ID                                                                     |
| QuoteId                  | Parent quote                                                           |
| State                    |                                                                        |
| LikelyQuoteAlternativeId | Alt. most likely to be accepted<br />used to calculate probable income |
| SentDate                 | When the version was sent to the customer                              |
| FollowupId               | The follow-up created when the version was sent                        |
| ExpirationDate           | The last date on which the offer is valid                              |
| Rank                     | The version number                                                     |

For a complete list of fields, see the [database reference][8].

[3]: ./add-quote-line

[4]: ./add-alternative

[5]: ./quote-document

[6]: ./place-order

[8]: ../../../../database/tables/quoteversion


## Related topics

- [Update Quote Version Prices](/en/api/reference/restful/agent/quote_agent/update-quote-version-prices.md)
- [Create Or Update Quote Version Attachments](/en/api/reference/restful/agent/quote_agent/create-or-update-quote-version-attachments.md)
- [IQuoteConnector](/en/api/plugins/quote-connectors/api/iquoteconnector.md)
- [NSQuoteAgent](/en/automation/crmscript/reference/CRMScript.NetServer.NSQuoteAgent.md)
- [SuperOffice.WebApi.Data.Quote UpdateQuoteVersionPricesRequest](/en/api/reference/webapi/SuperOffice.WebApi.Data.Quote_UpdateQuoteVersionPricesRequest.md)
- [SuperOffice.WebApi.Data.Quote CreateOrUpdateQuoteVersionAttachmentsRequest](/en/api/reference/webapi/SuperOffice.WebApi.Data.Quote_CreateOrUpdateQuoteVersionAttachmentsRequest.md)
