Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics SL (Archived)

Custom default value in field changing on save

(0) ShareShare
ReportReport
Posted on by

Hi all,

First time customizing a screen in SL and I'm trying to set the default value of the Terms ID (retrieved from the project level) on the Invoice and Adjustment Maintenance screen (BI.BAM.00) when creating a new draft. Currently, it defaults correctly while making the draft but when I click save to create it, the value is changed to the old default value coming from the customer contract terms level.

Code:

Private Sub Form1_Display()

End Sub
Sub Form1_Load()
    Call SqlCursor(c1, NOLEVEL)

End Sub
Sub cTerms_Default(newvalue$, retval%)
    Dim strSQLStmt As String
    Dim strTermsID As String
    Dim strProjectID As String
    
    strProjectID = GetObjectValue("cbill_project")
    
    strSQLStmt = ""
    strSQLStmt = "SELECT CASE WHEN c.termsid IS NULL OR c.termsid = '' THEN '00' ELSE c.termsid END AS termsid " & _
                 "FROM pjproj as p LEFT OUTER JOIN pjcont as c on p.contract = c.contract " & _
                 "WHERE p.project = " & SParm(strProjectID)
    'MsgBox strSQLStmt
    
    serr1 = SqlFetch1(c1, strSQLStmt, bContResult, LenB(bContResult))
    
    'SqlFetch returns 0 if records are returned or NOTFOUND if no records are returned
    If serr1 = NOTFOUND Then
        'Call MessBox("Error Locating Project " + SParm(strProjectID), MB_OK, "Can't Assign TermsID")
        Exit Sub
    Else
        'Check to see if the terms field is enabled or not so we don't modify posted records
        If cTerms.Enabled = True Then
            strTermsID = bContResult.termsid
            'Call MessBox("Assign TermsID: " + strTermsID, MB_OK, "Terms to assign")
            'Call SetObjectValue("cTerms", strTermsID)
            
            Call SetBufferValue("bpjinvhdr.ih_id18", strTermsID)
            
        End If
    End If
    
End Sub


On the field "cTerms" itself I've removed the values under default since we want to use the above logic and that is the only change I made to it. Any help or a pointer to the right direction would be greatly appreciated!

*This post is locked for comments

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Custom default value in field changing on save

    I am having a similar issue. I am able to set a default value on this screen when running (BI.BAM.00). I effectively use your code by call the method in Form1_Load(), maybe you could try that?

    My issue is in applying this same change to the Automatic Invoice Creation page (BI.AIC.00). This does not consider the customization from (BI.BAM.00) and I'm not sure where to re-implement. Does this require a SQL side change?

  • porterhaus4 Profile Picture
    porterhaus4 on at
    RE: Custom default value in field changing on save

    Hi Mark,

    I just tried adding that and it seemed to have no effect. The correct value is showing up until after I press the save button to create a new draft invoice which is when it changes to the default contract terms from the customer level.

    It is possible I'm not implementing a function correctly as I don't know what the difference between the form and the control is for that DispFields function. I'm using this pdf as a reference.

  • Suggested answer
    Mark E Profile Picture
    Mark E 6,405 on at
    RE: Custom default value in field changing on save

    Did you try adding Call DispFields("Form1","cterms") after Call SetBufferValue?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,735 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,466 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans