Skip to main content
Question

Auto Cancel QT based on Opportunity Lost status

  • January 28, 2022
  • 4 replies
  • 79 views

idrusm52
Jr Varsity III
Forum|alt.badge.img

Please advise how to make Customize or Workflow Action for Auto Canceling QT when Opportunity Status change to Lost.

 

Thanks,
Idrus

4 replies

Samvel Petrosov
Jr Varsity II
Forum|alt.badge.img+8

@idrusm52 are you talking about Sales Quote, Project Quote or Quote Type Sales Order?


idrusm52
Jr Varsity III
Forum|alt.badge.img
  • Author
  • Jr Varsity III
  • January 28, 2022

Hi @samvellaHBl7QVBU6C6KqXsC79Q 

It’s Sales Order Quote Type.


Sarahsmith
Freshman I
  • Freshman I
  • January 28, 2022

Reclamation is typically done in the application's fundamental() work. Check in the event that QGuiApplication::isSessionRestored() is valid...


mvolshteyn
Acumatica Moderator
Forum|alt.badge.img+3
  • Technical Account Manager in the ISV Team
  • January 28, 2022

@idrusm52 

You can synchronise an opportunity status with a sales order by means of the following unbound field in SOOrder:

public class SOOrderOpportunityStatusExt : PXCacheExtension<SOOrder>
    {
        public abstract class usrCROpportunityStatus : PX.Data.BQL.BqlString.Field<usrCROpportunityStatus> { }
        protected string _UsrCROpportunityStatus;
        [PXString(1, IsFixed = true)]
        [PXUIField(DisplayName = "Opportunity Status", Visibility = PXUIVisibility.SelectorVisible, Enabled = false)]
        [OpportunityWorkflow.States.List]

        
        public virtual string UsrCROpportunityStatus
        {
            get
            {
                return _UsrCROpportunityStatus;
            }
            set
            {
                _UsrCROpportunityStatus = value;
            }

        }

    }

you can calculate its value on the grid of SO501000 screen (where you should add this field)

public virtual void SOOrder_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
{
if (Base.Filter.Current.Action != SOCreateShipment.WellKnownActions.SOOrderScreen.CancelOrder)
return;
SOOrder row = (SOOrder)e.Row;

//PXFormulaAttribute.Evaluate<SOOrderOpportunityStatusExt.usrCROpportunityStatus>(sender, orderExt);
if (row == null) return;

CRRelation cRRelation = (CRRelation)PXSelectReadonly<CRRelation, Where<CRRelation.refNoteID, Equal<Required<CRRelation.refNoteID>>,
And<CRRelation.refEntityType, Equal<Required<CRRelation.refEntityType>>,
And<CRRelation.role, Equal<Required<CRRelation.role>>>>>>.Select(Base, row.NoteID, row.GetType().FullName, CRRoleTypeList.Source);
if (cRRelation != null)
{
CROpportunity opportunity =
(CROpportunity)PXSelectReadonly<CROpportunity, Where<CROpportunity.noteID, Equal<Required<CROpportunity.noteID>>>>.Select(Base, cRRelation.TargetNoteID);
if (opportunity != null)
{
SOOrderOpportunityStatusExt orderExt = row.GetExtension<SOOrderOpportunityStatusExt>();
orderExt.UsrCROpportunityStatus = opportunity.Status;
}
}
}

(see the 

 for additional info of link of sales orders with opportunites)

Then you can select the Cancel Order action the SO501000 screen and filter the grid by the Opportunity status = Lost. 

I’m not sure this approach (filter by unbound field) works well with schedules though. You can set it up with this condition but I did not manage to make it process any records 

You might want to make this field db stored (bound), but then you need to figure out how to update this field on changing the opportunity status (which is workflow-driven field). I believe it is doable.

Let me know if the ‘unbound field approach’ does not work and you need further assistance