web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics SL (Archived)

Custom default value in field changing on save

(0) ShareShare
ReportReport
Posted on by 2

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

I have the same question (0)
  • Suggested answer
    Mark E Profile Picture
    6,451 on at
    RE: Custom default value in field changing on save

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

  • porterhaus4 Profile Picture
    2 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
    Community Member Profile Picture
    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?

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics SL (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans