Can I Add a New Masking Rule?
Last updated
Was this helpful?
Was this helpful?
CREATE OR ALTER FUNCTION [dbo].[guard_mask_to_reverse]( @original NVARCHAR(MAX) ) RETURNS NVARCHAR(MAX)
AS
BEGIN
IF @original IS NULL RETURN NULL;
IF @original = '' RETURN '';
RETURN REVERSE(@original)
END;BEGIN
DECLARE @id INT;
DECLARE @templateRuleId INT;
DECLARE @now DATETIME;
--
-- Insert a top level masking rule.
--
INSERT INTO GuardianMaskingRule(name,functionName,isActive,createdDate,modifiedDate)
VALUES( 'Reverse', 'guard_mask_to_reverse([[VALUE]])', 1, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
;
--
-- Pick an existing rule which works on the same field types as the new rule.
-- Find the unique id assigned to the new rule.
--
SELECT @templateRuleId=id FROM GuardianMaskingRule WHERE name='Asterisks';
SELECT @id=id, @now=createdDate FROM GuardianMaskingRule WHERE name='Reverse';
--
-- Register the type of Salesforce fields supported by the masking rule.
--
INSERT INTO GuardianMaskingRuleFieldType(fieldTypeName, maskingRuleId
, createdDate, modifiedDate)
SELECT fieldTypeName, @id, @now, @now
FROM GuardianMaskingRuleFieldType
WHERE maskingRuleId = @templateRuleId;
END;