Inserting New Objects Using Batch Mode

This example demonstrates how to insert records into a class table and batch-update them to M-Files, including value list lookup and verification.

Review Target Table

SELECT * FROM MFCustomer;

View Lookup Values

SELECT mvli.*
FROM MFValueListItems mvli
INNER JOIN MFValueList mvl ON mvli.MFValueListID = mvl.id
WHERE mvli.Name = 'United Kingdom'
AND mvl.Name = 'Country';

Set Variable to Lookup

DECLARE @Country_ID INT;
SELECT @Country_ID = mvli.MFID
FROM MFValueListItems mvli
INNER JOIN MFValueList mvl ON mvli.MFValueListID = mvl.id
WHERE mvli.Name = 'United Kingdom'
AND mvl.Name = 'Country';

Insert New Record in Class Table

INSERT INTO dbo.MFCustomer (
    Address_Line_1,
    Address_Line_2,
    City,
    Country_ID,
    Customer_Name,
    StateProvince,
    Telephone_Number,
    Website,
    Process_ID
)
VALUES (
    'Building',
    'Street Name',
    'London',
    @Country_ID,
    'ABC Customer 2',
    'Hampshire',
    '90987098',
    'www.abccompany.com',
    1
);

Update Inserted Records from SQL into M-Files

EXEC spMFUpdateTable 'MFCustomer', 0;

Check Table

SELECT * FROM mfcustomer;